https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89722
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> --- I agree the macros obscure the problem. Here's a simpler test case: $ cat t.C && gcc -S -Wall -Wextra -Wignored-qualifiers t.C int f (void) { typedef const int ConstInt; return (ConstInt)1; } int g (const long *p) { return (__typeof__ (*p))1; } #if __cplusplus template <class T> T h (T*) { return (T)1; } int hh (const int *p) { return h (p); } #endif t.C: In function ‘int f()’: t.C:3:20: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers] 3 | return (ConstInt)1; | ^ t.C: In function ‘int g(const long int*)’: t.C:7:27: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers] 7 | return (__typeof__ (*p))1; | ^ But the code above doesn't trigger either warning when compiled as C. I think that suggests that either the manual should be updated to explain the difference or the two front ends should be made to behave the same way. As a data point, Clang doesn't warn in either C or C++ modes on this code so I wonder if G++ is being overly pedantic here, especially in the typeof cases. Btw., while G++ manages to avoid warning on template instantiation above, it does warn the explicit instantiation below. That seems like a bug to me since there's no way to avoid the warning if the template comes from some component the user has no control over. (Clang has the same problem.) gcc -O2 -S -Wall -Wextra -Wignored-qualifiers t.C template <class T> T h (T*) { return (T)1; } int hh (const int *p) { return h (p); } template const long h<const long> (const long*); t.C:11:10: warning: type qualifiers ignored on function return type [-Wignored-qualifiers] 11 | template const long h<const long> (const long*); | ^~~~~