[Bug c/101682] gcc incorrectly rejects C2x attributes after declaration-specifiers

eggert at gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Jul 29 23:11:33 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101682

--- Comment #2 from Paul Eggert <eggert at gnu dot org> ---
Clang's warnings are not a problem here, because in clang 12.0.0 (the current
release) __has_c_attribute(nodiscard) is false, so code like this works:

#ifndef __has_c_attribute
# define __has_c_attribute(x) 0
#endif
#if __has_c_attribute (nodiscard)
# define NODISCARD [[nodiscard]]
#else
# define NODISCARD
#endif
extern NODISCARD int f (void);
extern int NODISCARD g (void);
int NODISCARD h (void);
NODISCARD extern int i (void);
NODISCARD int j (void);

Although draft C2x recommends this sort of macro preprocessing and it works
with Clang 12.0.0, this code doesn't work with GCC 11.2.0 due to its
incompatibility with draft C2x.

This is more what the original code looked like, by the way; I removed the
macro preprocessing to simplify the original bug report.


More information about the Gcc-bugs mailing list