On Jun 8, 2024, at 2:23 PM, Bruno Haible <br...@clisp.org> wrote: > Adding to what Paul Eggert wrote: >> It looks like -Wc23-extensions is the problem. If you stop using it (or >> if you also use -std=gnu23), you shouldn't get those warnings. At least, >> that's the behavior I see with clang 18.1.6 (a bit later than your >> clang) on Fedora. >> >> -Wc23-extensions is more trouble than it's worth when programs (as is >> commonly the case) use C23 extensions only when available. > > You chose to desire warnings for C language constructs that are not > yet contained in C 23. You got such warnings.
True, but _my_ code uses no such constructs. My code is strict C11 (no extensions), not C23. My code uses only NODISCARD from Gnulib’s attribute.h: // attribute.h #define NODISCARD _GL_ATTRIBUTE_NODISCARD I did not define _GL_ATTRIBUTE_NODISCARD to use [[. It’s defined in config.h that’s generated by configure. IMHO, the code generated for config.h should not use [[ anywhere unless it knows for certain (via #if’s or other means) that the compiler supports [[ without warnings under any circumstances. That aside, as I mentioned previously, this generated line: # if defined __clang__ && defined __cplusplus seems wrong to me. Because __cplusplus is not defined, that #if fails which causes _GL_ATTRIBUTE_NODISCARD to be defined to use [[. IMHO, that line should be just: # if defined __clang__ or perhaps: # if defined __clang__ || __cplusplus /* ||, not && */ Indeed, the comment for the similarly defined _GL_ATTRIBUTE_MAYBE_UNUSED says: /* In C++ and C23, this is spelled [[__maybe_unused__]]. GCC's syntax is __attribute__ ((__unused__)). clang supports both syntaxes. Except that with clang ≥ 6, < 10, in C++ mode, __has_c_attribute (__maybe_unused__) yields true but the use of [[__maybe_unused__]] nevertheless produces a warning. */ Note that is says "In C++ and C23” which actually means “in _any_ C++ or C23” — that is “or” instead of “and” since a given program is either C _or_ C++ — and this seems to support my suggestion of changing “&& __cplusplus” to “|| __cplusplus”. > But you can deactivate Gnulib's definition of _GL_ATTRIBUTE_NODISCARD > by adding "-D_GL_ATTRIBUTE_NODISCARD=" to the CPPFLAGS or CFLAGS of your > compilation. But I _want_ it to figure out what D_GL_ATTRIBUTE_NODISCARD should expand into for me — which is the point of using that macro (via NODISCARD) in the first place. I don’t want to define it myself. - Paul