On Tue, Feb 20, 2018 at 08:09:39AM -0800, Matthew Wilcox wrote: > > I have a feature request relating to bitwise and enums. The following > does not work the way I would like it to: > > typedef __attribute__((bitwise)) enum { > FOO, > BAR, > } my_t; > > static my_t f(int a) > { > if (a) > return FOO; > return BAR; > }; > > sparse complains: > > test.c:10:16: warning: incorrect type in return expression (different base types) > test.c:10:16: expected restricted my_t > test.c:10:16: got int > > (line 10 is, of course 'return BAR'; since FOO has value 0, it does not warn > on line 9). > > I think it would be appropriate for the __attribute__((bitwise)) to > apply not just to 'my_t' but also to 'FOO' and 'BAR'. Yes, it's reasonable and intuitive. It would be nice to have Al Viro's option on this, though. > sparse doesn't whinge about this: > > typedef __attribute__((bitwise)) unsigned int my_t; > > typedef enum { > FOO = (__attribute__((force)) my_t)0, > BAR = (__attribute__((force)) my_t)1, > } my_t; > > although GCC does complain about redefining a typedef. Maybe sparse > should also warn about that? That's clearly a bug. > Oh, and I'd also like sparse to permit this: > > typedef __attribute__((bitwise)) enum { > FOO = 1, > BAR = 2, > BAZ = 4, > QUUX = 8, > WIBBLE = 0x10, > } my_t; > > (if you're defining enums for a bitwise type, you're almost certainly > defining individual bits, so you want to do explicit assignment of values) Sure. For me, it's implied by your first request. Thanks for the feedback. I'll see what I can do in the coming days. -- Luc -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html