Minimal test-case (repros with 7.1: https://godbolt.org/g/A2dTCP): $ cat tc.c const int i; const typeof(i) j; $ gcc -std=gnu89 -pedantic tc.c 2:17: warning: duplicate 'const' [-Wpedantic] const typeof(i) j; Expected behavior: no duplicate const warning when there's only one `const` on the decl for `j`. While the current behavior is understandable, I think it would be good to relax the warning in this case. typeof is often used in macros, so silencing this warning isn't always trivial. Since typeof is also a language extension, I don't believe that C89 6.5.3 (which I assume is the only reason GCC is emitting these complaints in the first place) needs to apply here. Thank you for your time :)
Other discussions: LKML: https://patchwork.kernel.org/patch/9693821/ Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=723720 LLVM: https://bugs.llvm.org/show_bug.cgi?id=32985
We're supposed to complain for const const int x; and typedef const int t; const t x; and I think we should thus also warn for this (-std=gnu89 -pedantic only). const int a; const __typeof(a) x; because __typeof() doesn't strip outermost type qualifications. There were discussion about adding __nonqual_typeof() but that hasn't been added yet.
Thanks for the response! From the standpoint of consistency, I agree. My point is more that GCC isn't bound by the standard to be as strict with `typeof`, and making an exception for `typeof` here would make it easier to use in macros. I believe the gain in usability here outweighs the cost of having this inconsistency. (I also feel that this warning in general isn't useful when the only "duplicate" const has been inferred from an expression, but it seems that __auto_type has the same "duplicate const" behavior as typeof, so...)
We can close this bug. LLVM will match GCC here: https://reviews.llvm.org/D52248
Oh, note in the typedef case: typedef const int t; const t x; It seems that for -std=c89 (non pedantic, non GNU), GCC does not warn. That seems to violate C90 6.5.3 constraints: "The same type qualifier shall not appear more than once in the same specifier-list or qualifier-list, either directly or via one or more typedefs."
The observation in comment 5 probably warrants its own bug report. George, do you agree with closing this?
Forked: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87435
> George, do you agree with closing this? Sounds good to me. Thanks everyone!