https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89734
Bug ID: 89734 Summary: const qualifier on return type not erased inside __typeof__ Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: pascal_cuoq at hotmail dot com Target Milestone: --- I think that this report is related to the implementation of a resolution from DR 423 in 2017: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39985#c5 I would expect the following C program to be accepted: #define CONST(x) __typeof__(const __typeof__(x)) #define POINTER(x) __typeof__(__typeof__(x) *) #define ARRAY(x, n) __typeof__(__typeof__(x)[n]) #define FUNCTION(x, y) __typeof__(__typeof__(y)(__typeof__(x))) extern int (* const p(int))[5]; FUNCTION(int, CONST(POINTER(ARRAY(int,5)))) p; According to Compiler Explorer, it is accepted by Clang, and by GCC version up to 6.3, but not by GCC version 7 and above, which complains: error: conflicting types for 'p' Compiler Explorer link: https://gcc.godbolt.org/z/c_9JTu This may be related to how function types are handled inside __typeof__. If the const attribute is not erased inside __typeof__, then it would not match the type build for a plain declaration, where the const attribute is erased since revision 236231. If that were the case, then a solution would be to make the __typeof__ extension more uniform with the rest of the language.