[gcc r15-9666] libstdc++: Remove #warning from <ciso646> for C++17 [PR120187]
Jonathan Wakely
redi@gcc.gnu.org
Mon May 12 20:27:01 GMT 2025
https://gcc.gnu.org/g:506cb05479ee04c724eb0ebde07d2e9062efb264
commit r15-9666-g506cb05479ee04c724eb0ebde07d2e9062efb264
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri May 9 10:23:05 2025 +0100
libstdc++: Remove #warning from <ciso646> for C++17 [PR120187]
Although <ciso646> was removed from C++20, it was not formally
deprecated in C++17. In contrast, <ctgmath>, <cstdalign>, etc. were
formally deprecated in C++17 before being removed in C++20.
Due to the widespread convention of including <ciso646> to detect
implementation-specific macros (such as _GLIBCXX_RELEASE) it causes
quite a lot of noise to issue deprecation warnings in C++17 mode. The
recommendation to include <version> instead does work for recent
compilers, even in C++17 mode, but isn't portable to older compilers
that don't provide <version> yet (e.g. GCC 8).
There are also potential objections to including <version> pre-C++20
when it wasn't defined by the standard. I don't have much sympathy for
this position, because including <ciso646> for implementation-specific
macros wasn't part of the C++17 standard either. It's no more
non-standard to rely on <version> being present and defining those
macros than to rely on <ciso646> defining them, and __has_include can be
used to detect whether <version> is present. However, <ciso646> is being
used in the wild by popular libraries like Abseil and we can't change
versions of those that have already been released.
This removes the #warning in <ciso646> for C++17 mode, so that we only
emit diagnostics for C++20 and later. With this change, including
<ciso646> in C++20 or later gives an error if _GLIBCXX_USE_DEPRECATED is
defined to zero, otherwise a warning if -Wdeprecated is enabled,
otherwise no diagnostic is given.
This also adds "@since C++11 (removed in C++20)" to the Doxygen @file
comments in all the relevant headers.
The test for <ciso646> needs to be updated to no longer expect a warning
for c++17_only. A new test is added to ensure that we get a warning
instead of an error when -D_GLIBCXX_USE_DEPRECATED=0 is not used.
libstdc++-v3/ChangeLog:
PR libstdc++/120187
* include/c_global/ciso646: Only give deprecated warning for
C++20 and later.
* include/c_global/ccomplex: Add @since to Doxygen comment.
* include/c_global/cstdalign: Likewise.
* include/c_global/cstdbool: Likewise.
* include/c_global/ctgmath: Likewise.
* testsuite/18_support/headers/ciso646/macros.cc: Remove
dg-warning for c++17_only effective target.
* testsuite/18_support/headers/ciso646/macros-2.cc: New test.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
(cherry picked from commit af062510f4179aa7b13e632f77593deee8fe29f2)
Diff:
---
libstdc++-v3/include/c_global/ccomplex | 2 ++
libstdc++-v3/include/c_global/ciso646 | 18 +++++++++++-------
libstdc++-v3/include/c_global/cstdalign | 2 ++
libstdc++-v3/include/c_global/cstdbool | 2 ++
libstdc++-v3/include/c_global/ctgmath | 2 ++
.../testsuite/18_support/headers/ciso646/macros-2.cc | 7 +++++++
.../testsuite/18_support/headers/ciso646/macros.cc | 1 -
7 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/libstdc++-v3/include/c_global/ccomplex b/libstdc++-v3/include/c_global/ccomplex
index 7044cf74f6c7..a39273f4a8a2 100644
--- a/libstdc++-v3/include/c_global/ccomplex
+++ b/libstdc++-v3/include/c_global/ccomplex
@@ -24,6 +24,8 @@
/** @file include/ccomplex
* This is a Standard C++ Library header.
+ *
+ * @since C++11 (removed in C++20)
*/
#ifndef _GLIBCXX_CCOMPLEX
diff --git a/libstdc++-v3/include/c_global/ciso646 b/libstdc++-v3/include/c_global/ciso646
index a663e04caf08..6dec7df1631f 100644
--- a/libstdc++-v3/include/c_global/ciso646
+++ b/libstdc++-v3/include/c_global/ciso646
@@ -28,6 +28,8 @@
*
* This is the C++ version of the Standard C Library header @c iso646.h,
* which is empty in C++.
+ *
+ * @since C++11 (removed in C++20)
*/
#ifndef _GLIBCXX_CISO646
#define _GLIBCXX_CISO646
@@ -38,13 +40,15 @@
#include <bits/c++config.h>
-#if __cplusplus >= 202002L && ! _GLIBCXX_USE_DEPRECATED
-# error "<ciso646> is not a standard header in C++20, use <version> to detect implementation-specific macros"
-#elif __cplusplus >= 201703L && defined __DEPRECATED
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wc++23-extensions"
-# warning "<ciso646> is deprecated in C++17, use <version> to detect implementation-specific macros"
-# pragma GCC diagnostic pop
+#if __cplusplus >= 202002L
+# if ! _GLIBCXX_USE_DEPRECATED
+# error "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros"
+# elif defined __DEPRECATED
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wc++23-extensions"
+# warning "<ciso646> is not a standard header since C++20, use <version> to detect implementation-specific macros"
+# pragma GCC diagnostic pop
+# endif
#endif
#endif
diff --git a/libstdc++-v3/include/c_global/cstdalign b/libstdc++-v3/include/c_global/cstdalign
index 92e0ad633089..41ce5065ca08 100644
--- a/libstdc++-v3/include/c_global/cstdalign
+++ b/libstdc++-v3/include/c_global/cstdalign
@@ -24,6 +24,8 @@
/** @file include/cstdalign
* This is a Standard C++ Library header.
+ *
+ * @since C++11 (removed in C++20)
*/
#ifndef _GLIBCXX_CSTDALIGN
diff --git a/libstdc++-v3/include/c_global/cstdbool b/libstdc++-v3/include/c_global/cstdbool
index e75f56cd5a12..5933d7d96945 100644
--- a/libstdc++-v3/include/c_global/cstdbool
+++ b/libstdc++-v3/include/c_global/cstdbool
@@ -24,6 +24,8 @@
/** @file include/cstdbool
* This is a Standard C++ Library header.
+ *
+ * @since C++11 (removed in C++20)
*/
#ifndef _GLIBCXX_CSTDBOOL
diff --git a/libstdc++-v3/include/c_global/ctgmath b/libstdc++-v3/include/c_global/ctgmath
index 0a5a0e79b297..b708878ef127 100644
--- a/libstdc++-v3/include/c_global/ctgmath
+++ b/libstdc++-v3/include/c_global/ctgmath
@@ -24,6 +24,8 @@
/** @file include/ctgmath
* This is a Standard C++ Library header.
+ *
+ * @since C++11 (removed in C++20)
*/
#ifndef _GLIBCXX_CTGMATH
diff --git a/libstdc++-v3/testsuite/18_support/headers/ciso646/macros-2.cc b/libstdc++-v3/testsuite/18_support/headers/ciso646/macros-2.cc
new file mode 100644
index 000000000000..a49292408a33
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/headers/ciso646/macros-2.cc
@@ -0,0 +1,7 @@
+// { dg-options " -Wdeprecated -fno-operator-names" }
+// { dg-do preprocess }
+
+// Should get a warning for C++20 and up without -D_GLIBCXX_USE_DEPRECATED=0
+// { dg-warning "not a standard header" "" { target c++20 } 0 }
+
+#include "macros.cc"
diff --git a/libstdc++-v3/testsuite/18_support/headers/ciso646/macros.cc b/libstdc++-v3/testsuite/18_support/headers/ciso646/macros.cc
index ab3a041de062..0cb5168d5ec9 100644
--- a/libstdc++-v3/testsuite/18_support/headers/ciso646/macros.cc
+++ b/libstdc++-v3/testsuite/18_support/headers/ciso646/macros.cc
@@ -3,7 +3,6 @@
#include <ciso646>
-// { dg-warning "deprecated" "" { target c++17_only } 0 }
// { dg-error "not a standard header" "" { target c++20 } 0 }
#ifdef and
More information about the Libstdc++-cvs
mailing list