[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sr #111072] "[[]] attributes are a C23 extension warning" with clang
From: |
anonymous |
Subject: |
[sr #111072] "[[]] attributes are a C23 extension warning" with clang |
Date: |
Fri, 7 Jun 2024 19:49:01 -0400 (EDT) |
URL:
<https://savannah.gnu.org/support/?111072>
Summary: "[[]] attributes are a C23 extension warning" with
clang
Group: Autoconf
Submitter: None
Submitted: Fri 07 Jun 2024 11:49:01 PM UTC
Priority: 5 - Unprioritized
Severity: 3 - Normal
Status: None
Privacy: Public
Assigned to: None
Originator Email: paul@lucasmail.org
Open/Closed: Open
Discussion Lock: Any
Operating System: *BSD
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Fri 07 Jun 2024 11:49:01 PM UTC By: Anonymous
Hello —
Recently, I started getting warnings like:
./slist.h:170:1: warning: [[]] attributes are a C23 extension
[-Wc23-extensions]
170 | NODISCARD
| ^
../lib/attribute.h:143:19: note: expanded from macro 'NODISCARD'
143 | #define NODISCARD _GL_ATTRIBUTE_NODISCARD
| ^
./config.h:1392:37: note: expanded from macro '_GL_ATTRIBUTE_NODISCARD'
1392 | # define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
| ^
Specifically, the value defined for NODISCARD defined in config.h as generated
by configure as generated by autoconf causes the warning.
The relevant section from config.h is:
#ifndef _GL_ATTRIBUTE_NODISCARD
# ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
# if defined __clang__ && defined __cplusplus
/* With clang up to 15.0.6 (at least), in C++ mode, [[__nodiscard__]]
produces
a warning.
The 1000 below means a yet unknown threshold. When clang++ version X
starts supporting [[__nodiscard__]] without warning about it, you can
replace the 1000 with X. */
# if __clang_major__ >= 1000
# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
# endif
# elif _GL_HAVE___HAS_C_ATTRIBUTE
# if __has_c_attribute (__nodiscard__)
# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
# endif
# endif
# endif
# if !defined _GL_ATTRIBUTE_NODISCARD && _GL_HAS_ATTRIBUTE
(warn_unused_result)
# define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))
# endif
# ifndef _GL_ATTRIBUTE_NODISCARD
# define _GL_ATTRIBUTE_NODISCARD
# endif
#endif
I think the problem is this line:
# if defined __clang__ && defined __cplusplus
My project is a C project, not C++, so __cplusplus is not defined so that #if
fails which means this part happens:
# elif _GL_HAVE___HAS_C_ATTRIBUTE
# if __has_c_attribute (__nodiscard__)
# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
# endif
In this block, no check for __clang_major__ is done, so it always defines
_GL_ATTRIBUTE_NODISCARD to [[__nodiscard__]] and clang warns.
I don't think the && __cplusplus should be there at all. Attributes using [[
are supported in C23 or later or C++11 or later. Why not use
__STDC_VERSION__?
FYI:
$ clang --version
FreeBSD clang version 18.1.5 (https://github.com/llvm/llvm-project.git
llvmorg-18.1.5-0-g617a15a9eac9)
Target: x86_64-unknown-freebsd14.1
Thread model: posix
InstalledDir: /usr/bin
$ autoconf --version
autoconf (GNU Autoconf) 2.72
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>,
<https://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David J. MacKenzie and Akim Demaille.
— Paul
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/support/?111072>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [sr #111072] "[[]] attributes are a C23 extension warning" with clang,
anonymous <=