This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] RFC: PR78905 define _GLIBCXX_RELEASE macro
On 17/01/17 23:17 +0000, Jonathan Wakely wrote:
On 17/01/17 17:16 -0500, Ed Smith-Rowland wrote:
On 01/17/2017 04:55 PM, Ed Smith-Rowland wrote:
On 01/17/2017 12:25 PM, Jonathan Wakely wrote:
As I said in https://gcc.gnu.org/ml/libstdc++/2017-01/msg00109.html
the __GLIBCXX__ macro is useless, but is the closest thing we have to
a version macro for libstdc++. This matters when using libstdc++ with
Clang or Intel icc or other compilers, because you can't check the
__GNUC__ macro. I've seen several requests for a way to check the
libstdc++ version, or complaints that there is no way to do it.
This patch adds a new _GLIBCXX_RELEASE macro that contains the same
value as __GNUC__ i.e. the major release number.
- Yes, it only contains the major number. We could in theory have
_GLIBCXX_MAJOR and _GLIBCXX_MINOR instead, but between
_GLIBCXX_RELEASE and __GLIBCXX__ you can identify the release branch
and a date within that branch.
- The name is "RELEASE" because we used to define _GLIBCXX_VERSION
many years ago, but it was a string literal and this is an integer.
To avoid problems for any old code checking for _GLIBCXX_VERSION I
chose a different name.
Thoughts?
PR libstdc++/78905
* include/Makefile.am (_GLIBCXX_RELEASE): Set value.
* include/Makefile.in: Regenerate.
* include/bits/c++config (_GLIBCXX_RELEASE): Add #define.
* testsuite/ext/profile/mutex_extensions_neg.cc: Use lineno of 0 in
dg-error.
This might stop people from complaining about stub implementations.
Yes, that's one way it could be helpful.
It would also help with ABI breaks and as a coarse-grained feature-macro.
Yes, the PR mentioned in the ChangeLog entry above is basically a
request for a feature-test macro for <regex>, but SD-6 doesn't define
macros for C++11 features (because it was written long after 2011 and
most implementations have full C++11 support now anyway).
It seems like we'd want to backport this of course.
I'm undecided. Would it still be useful to define _GLIBCXX_RELEASE=6
for the 6.4.0 release, even though it wasn't defined for 6.3.0? Maybe
it would be simpler to only define it from GCC 7 onwards. Or maybe
doing it for 5.5 and 6.4 would still be useful in some cases, even if
not in all cases.
Of course you want more feedback from packagers.
Ed
I'm assuming this is really directed at folks who borrow only the
library and not the rest of gcc.
Otherwise we could just use the main macro.
Yes, exactly. It's only useful when using libstdc++ with a non-GCC
compiler. That's fairly common, and if we remove this obstacle then
it's slightly easier to do, and there will be a good answer to
questions like:
http://stackoverflow.com/questions/21622561/how-to-detect-the-libstdc-version-in-clang
And Boost wouldn't need to do this for future releases:
https://github.com/boostorg/config/blob/develop/include/boost/config/stdlib/libstdcpp3.hpp#L116
If we backported it then Boost.Config could look for _GLIBCXX_RELEASE
first, and if it finds it use it, otherwise try that __has_include
dance.
Here's what I'm committing, which also documents the new macro, and
updates the docs for the __GLIBCXX__ and _GLIBCXX_VERSION macros.
Tested powerpc64le-linux, committed to trunk.
commit 2977fed1b891bf50f1c20079bb912bde82b05b61
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Jan 19 16:24:37 2017 +0000
PR78905 define _GLIBCXX_RELEASE macro
PR libstdc++/78905
* doc/xml/manual/abi.xml (abi.versioning.history): Add markup to
macro names, filenames, and literal values. Document _GLIBCXX_RELEASE.
Document that the deprecated _GLIBCXX_VERSION macro was removed for
the 4.0.0 release.
* doc/html/*: Regenerate.
* include/Makefile.am (_GLIBCXX_RELEASE): Set value.
* include/Makefile.in: Regenerate.
* include/bits/c++config (_GLIBCXX_RELEASE): Add #define.
* testsuite/ext/profile/mutex_extensions_neg.cc: Use lineno of 0 in
dg-error.
diff --git a/libstdc++-v3/doc/xml/manual/abi.xml b/libstdc++-v3/doc/xml/manual/abi.xml
index c818bd8..f2b2ec3 100644
--- a/libstdc++-v3/doc/xml/manual/abi.xml
+++ b/libstdc++-v3/doc/xml/manual/abi.xml
@@ -378,22 +378,26 @@ compatible.
<listitem><para>GCC 3.2: <code>-fabi-version=1</code></para></listitem>
<listitem><para>GCC 3.3: <code>-fabi-version=1</code></para></listitem>
<listitem><para>GCC 3.4, GCC 4.x: <code>-fabi-version=2</code> <emphasis>(Incompatible with previous)</emphasis></para></listitem>
+ <listitem><para>GCC 5 and higher: <code>-fabi-version=0</code> <emphasis>(See GCC manual for meaning)</emphasis></para></listitem>
</itemizedlist>
<para/>
</listitem>
<listitem>
<para>Incremental bumping of a library pre-defined macro. For releases
- before 3.4.0, the macro is __GLIBCPP__. For later releases, it's
- __GLIBCXX__. (The libstdc++ project generously changed from CPP to
- CXX throughout its source to allow the "C" pre-processor the CPP
- macro namespace.) These macros are defined as the date the library
- was released, in compressed ISO date format, as an unsigned long.
+ before 3.4.0, the macro is <symbol>__GLIBCPP__</symbol>. For later
+ releases, it's <symbol>__GLIBCXX__</symbol>. (The libstdc++ project
+ generously changed from CPP to CXX throughout its source to allow the
+ "C" pre-processor the CPP macro namespace.) These macros are defined
+ as the date the library was released, in compressed ISO date format,
+ as an integer constant.
</para>
<para>
- This macro is defined in the file "c++config" in the
- "libstdc++-v3/include/bits" directory. Up to GCC 4.1.0, it was
+ This macro is defined in the file
+ <filename class="headerfile">c++config</filename> in the
+ <filename class="directory">libstdc++-v3/include/bits</filename>
+ directory. Up to GCC 4.1.0, it was
changed every night by an automated script. Since GCC 4.1.0 it is set
during configuration to the same value as
<filename>gcc/DATESTAMP</filename>, so for an official release its value
@@ -404,51 +408,54 @@ compatible.
</para>
<para>
- This macro is not useful for determining whether a particular feature is
- supported by the version of libstdc++ you are using. The date of a release
- might be after a feature was added to the development trunk, but the
- release could be from an older branch. For example, in the 5.4.0 release
- the macro has the value 20160603 which is greater than the 20160427 value
- of the macro in the 6.1.0 release, but there are features supported in the
- 6.1.0 release that are not supported in 5.4.0 release.
+ This macro can be used in code to detect whether the C++ Standard Library
+ implementation in use is libstdc++, but is not useful for detecting the
+ libstdc++ version, nor whether particular features are supported.
+ The macro value might be a date after a feature was added to the
+ development trunk, but the release could be from an older branch without
+ the feature. For example, in the 5.4.0 release the macro has the value
+ <literal>20160603</literal> which is greater than the
+ <literal>20160427</literal> value of the macro in the 6.1.0 release,
+ but there are features supported in the 6.1.0 release that are not
+ supported in 5.4.0 release.
You also can't test for the the exact values listed below to try and
identify a release, because a snapshot taken from the gcc-5-branch on
2016-04-27 would have the same value for the macro as the 6.1.0 release
despite being a different version.
Many GNU/Linux distributions build their GCC packages from snapshots, so
- the macro can have dates that doesn't correspond to official releases.
+ the macro can have dates that don't correspond to official releases.
</para>
<para>
It is versioned as follows:
</para>
<itemizedlist>
- <listitem><para>GCC 3.0.0: 20010615</para></listitem>
- <listitem><para>GCC 3.0.1: 20010819</para></listitem>
- <listitem><para>GCC 3.0.2: 20011023</para></listitem>
- <listitem><para>GCC 3.0.3: 20011220</para></listitem>
- <listitem><para>GCC 3.0.4: 20020220</para></listitem>
- <listitem><para>GCC 3.1.0: 20020514</para></listitem>
- <listitem><para>GCC 3.1.1: 20020725</para></listitem>
- <listitem><para>GCC 3.2.0: 20020814</para></listitem>
- <listitem><para>GCC 3.2.1: 20021119</para></listitem>
- <listitem><para>GCC 3.2.2: 20030205</para></listitem>
- <listitem><para>GCC 3.2.3: 20030422</para></listitem>
- <listitem><para>GCC 3.3.0: 20030513</para></listitem>
- <listitem><para>GCC 3.3.1: 20030804</para></listitem>
- <listitem><para>GCC 3.3.2: 20031016</para></listitem>
- <listitem><para>GCC 3.3.3: 20040214</para></listitem>
- <listitem><para>GCC 3.4.0: 20040419</para></listitem>
- <listitem><para>GCC 3.4.1: 20040701</para></listitem>
- <listitem><para>GCC 3.4.2: 20040906</para></listitem>
- <listitem><para>GCC 3.4.3: 20041105</para></listitem>
- <listitem><para>GCC 3.4.4: 20050519</para></listitem>
- <listitem><para>GCC 3.4.5: 20051201</para></listitem>
- <listitem><para>GCC 3.4.6: 20060306</para></listitem>
- <listitem><para>GCC 4.0.0: 20050421</para></listitem>
- <listitem><para>GCC 4.0.1: 20050707</para></listitem>
- <listitem><para>GCC 4.0.2: 20050921</para></listitem>
- <listitem><para>GCC 4.0.3: 20060309</para></listitem>
+ <listitem><para>GCC 3.0.0: <literal>20010615</literal></para></listitem>
+ <listitem><para>GCC 3.0.1: <literal>20010819</literal></para></listitem>
+ <listitem><para>GCC 3.0.2: <literal>20011023</literal></para></listitem>
+ <listitem><para>GCC 3.0.3: <literal>20011220</literal></para></listitem>
+ <listitem><para>GCC 3.0.4: <literal>20020220</literal></para></listitem>
+ <listitem><para>GCC 3.1.0: <literal>20020514</literal></para></listitem>
+ <listitem><para>GCC 3.1.1: <literal>20020725</literal></para></listitem>
+ <listitem><para>GCC 3.2.0: <literal>20020814</literal></para></listitem>
+ <listitem><para>GCC 3.2.1: <literal>20021119</literal></para></listitem>
+ <listitem><para>GCC 3.2.2: <literal>20030205</literal></para></listitem>
+ <listitem><para>GCC 3.2.3: <literal>20030422</literal></para></listitem>
+ <listitem><para>GCC 3.3.0: <literal>20030513</literal></para></listitem>
+ <listitem><para>GCC 3.3.1: <literal>20030804</literal></para></listitem>
+ <listitem><para>GCC 3.3.2: <literal>20031016</literal></para></listitem>
+ <listitem><para>GCC 3.3.3: <literal>20040214</literal></para></listitem>
+ <listitem><para>GCC 3.4.0: <literal>20040419</literal></para></listitem>
+ <listitem><para>GCC 3.4.1: <literal>20040701</literal></para></listitem>
+ <listitem><para>GCC 3.4.2: <literal>20040906</literal></para></listitem>
+ <listitem><para>GCC 3.4.3: <literal>20041105</literal></para></listitem>
+ <listitem><para>GCC 3.4.4: <literal>20050519</literal></para></listitem>
+ <listitem><para>GCC 3.4.5: <literal>20051201</literal></para></listitem>
+ <listitem><para>GCC 3.4.6: <literal>20060306</literal></para></listitem>
+ <listitem><para>GCC 4.0.0: <literal>20050421</literal></para></listitem>
+ <listitem><para>GCC 4.0.1: <literal>20050707</literal></para></listitem>
+ <listitem><para>GCC 4.0.2: <literal>20050921</literal></para></listitem>
+ <listitem><para>GCC 4.0.3: <literal>20060309</literal></para></listitem>
<listitem><para>
GCC 4.1.0 and later: the GCC release date, as shown in the
<link xmlns:xlink="http://www.w3.org/1999/xlink"
@@ -461,41 +468,63 @@ compatible.
<listitem>
<para>
- Incremental bumping of a library pre-defined macro,
- _GLIBCPP_VERSION. This macro is defined as the released version of
- the library, as a string literal. This is only implemented in
- GCC 3.1.0 releases and higher, and is deprecated in 3.4 (where it
- is called _GLIBCXX_VERSION).
+ Since GCC 7, incremental bumping of a library pre-defined macro,
+ <symbol>_GLIBCXX_RELEASE</symbol>. This macro is defined to the GCC
+ major version that the libstdc++ headers belong to, as an integer constant.
+ When compiling with GCC it has the same value as GCC's pre-defined
+ macro <symbol>__GNUC__</symbol>.
+ This macro can be used when libstdc++ is used with a non-GNU
+ compiler where <symbol>__GNUC__</symbol> is not defined, or has a
+ different value that doesn't correspond to the libstdc++ version.
</para>
<para>
- This macro is defined in the file "c++config" in the
- "libstdc++-v3/include/bits" directory and is generated
- automatically by autoconf as part of the configure-time generation
- of config.h.
+ This macro is defined in the file
+ <filename class="headerfile">c++config</filename> in the
+ <filename class="directory">libstdc++-v3/include/bits</filename>
+ directory and is generated automatically by autoconf as part of the
+ configure-time generation of
+ <filename class="headerfile">config.h</filename> and subsequently
+ <filename class="headerfile"><bits/c++config.h></filename>.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ Historically, incremental bumping of a library pre-defined macro,
+ <symbol>_GLIBCPP_VERSION</symbol>. This macro was defined as the
+ released version of the library, as a string literal. This was only
+ implemented in GCC 3.1.0 releases and higher, and was deprecated in
+ 3.4.x (where it was called <symbol>_GLIBCXX_VERSION</symbol>),
+ and is not defined in 4.0.0 and higher.
+ </para>
+
+ <para>
+ This macro is defined in the same file as
+ <symbol>_GLIBCXX_RELEASE</symbol>, described above.
</para>
<para>
It is versioned as follows:
</para>
<itemizedlist>
- <listitem><para>GCC 3.0.0: "3.0.0"</para></listitem>
- <listitem><para>GCC 3.0.1: "3.0.0" (Error, should be "3.0.1")</para></listitem>
- <listitem><para>GCC 3.0.2: "3.0.0" (Error, should be "3.0.2")</para></listitem>
- <listitem><para>GCC 3.0.3: "3.0.0" (Error, should be "3.0.3")</para></listitem>
- <listitem><para>GCC 3.0.4: "3.0.0" (Error, should be "3.0.4")</para></listitem>
- <listitem><para>GCC 3.1.0: "3.1.0"</para></listitem>
- <listitem><para>GCC 3.1.1: "3.1.1"</para></listitem>
- <listitem><para>GCC 3.2.0: "3.2"</para></listitem>
- <listitem><para>GCC 3.2.1: "3.2.1"</para></listitem>
- <listitem><para>GCC 3.2.2: "3.2.2"</para></listitem>
- <listitem><para>GCC 3.2.3: "3.2.3"</para></listitem>
- <listitem><para>GCC 3.3.0: "3.3"</para></listitem>
- <listitem><para>GCC 3.3.1: "3.3.1"</para></listitem>
- <listitem><para>GCC 3.3.2: "3.3.2"</para></listitem>
- <listitem><para>GCC 3.3.3: "3.3.3"</para></listitem>
- <listitem><para>GCC 3.4: "version-unused"</para></listitem>
- <listitem><para>GCC 4.x: "version-unused"</para></listitem>
+ <listitem><para>GCC 3.0.0: <literal>"3.0.0"</literal></para></listitem>
+ <listitem><para>GCC 3.0.1: <literal>"3.0.0"</literal> (Error, should be <literal>"3.0.1"</literal>)</para></listitem>
+ <listitem><para>GCC 3.0.2: <literal>"3.0.0"</literal> (Error, should be <literal>"3.0.2"</literal>)</para></listitem>
+ <listitem><para>GCC 3.0.3: <literal>"3.0.0"</literal> (Error, should be <literal>"3.0.3"</literal>)</para></listitem>
+ <listitem><para>GCC 3.0.4: <literal>"3.0.0"</literal> (Error, should be <literal>"3.0.4"</literal>)</para></listitem>
+ <listitem><para>GCC 3.1.0: <literal>"3.1.0"</literal></para></listitem>
+ <listitem><para>GCC 3.1.1: <literal>"3.1.1"</literal></para></listitem>
+ <listitem><para>GCC 3.2.0: <literal>"3.2"</literal></para></listitem>
+ <listitem><para>GCC 3.2.1: <literal>"3.2.1"</literal></para></listitem>
+ <listitem><para>GCC 3.2.2: <literal>"3.2.2"</literal></para></listitem>
+ <listitem><para>GCC 3.2.3: <literal>"3.2.3"</literal></para></listitem>
+ <listitem><para>GCC 3.3.0: <literal>"3.3"</literal></para></listitem>
+ <listitem><para>GCC 3.3.1: <literal>"3.3.1"</literal></para></listitem>
+ <listitem><para>GCC 3.3.2: <literal>"3.3.2"</literal></para></listitem>
+ <listitem><para>GCC 3.3.3: <literal>"3.3.3"</literal></para></listitem>
+ <listitem><para>GCC 3.4: <literal>"version-unused"</literal></para></listitem>
+ <listitem><para>GCC 4 and later: not defined</para></listitem>
</itemizedlist>
<para/>
</listitem>
@@ -508,7 +537,7 @@ compatible.
</para>
<para>
All C++ includes are installed in
- <filename class="directory">include/c++</filename>, then nest in a
+ <filename class="directory">include/c++</filename>, then nested in a
directory hierarchy corresponding to the C++ compiler's released
version. This version corresponds to the variable "gcc_version" in
"libstdc++-v3/acinclude.m4," and more details can be found in that
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index dfdceb3..3703bd1 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -1238,6 +1238,7 @@ ${host_builddir}/c++config.h: ${CONFIG_HEADER} \
stamp-cxx11-abi \
stamp-allocator-new
@date=`cat ${toplevel_srcdir}/gcc/DATESTAMP` ;\
+ release=`sed 's/^\([0-9]*\).*$$/\1/' ${toplevel_srcdir}/gcc/BASE-VER` ;\
ns_version=`cat stamp-namespace-version` ;\
visibility=`cat stamp-visibility` ;\
externtemplate=`cat stamp-extern-template` ;\
@@ -1249,6 +1250,7 @@ ${host_builddir}/c++config.h: ${CONFIG_HEADER} \
${CONFIG_HEADER} > /dev/null 2>&1 \
&& ldbl_compat='s,^#undef _GLIBCXX_LONG_DOUBLE_COMPAT$$,#define _GLIBCXX_LONG_DOUBLE_COMPAT 1,' ;\
sed -e "s,define __GLIBCXX__,define __GLIBCXX__ $$date," \
+ -e "s,define _GLIBCXX_RELEASE,define _GLIBCXX_RELEASE $$release," \
-e "s,define _GLIBCXX_INLINE_VERSION, define _GLIBCXX_INLINE_VERSION $$ns_version," \
-e "s,define _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY, define _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY $$visibility," \
-e "s,define _GLIBCXX_EXTERN_TEMPLATE$$, define _GLIBCXX_EXTERN_TEMPLATE $$externtemplate," \
diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 0cc1865..bc1ab5f 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -30,7 +30,10 @@
#ifndef _GLIBCXX_CXX_CONFIG_H
#define _GLIBCXX_CXX_CONFIG_H 1
-// The current version of the C++ library in compressed ISO date format.
+// The major release number for the GCC release the C++ library belongs to.
+#define _GLIBCXX_RELEASE
+
+// The datestamp of the C++ library in compressed ISO date format.
#define __GLIBCXX__
// Macros for various attributes.
diff --git a/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc b/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
index 32a4e91..645aa24 100644
--- a/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
+++ b/libstdc++-v3/testsuite/ext/profile/mutex_extensions_neg.cc
@@ -25,7 +25,7 @@
#include <vector>
-// { dg-error "multiple inlined namespaces" "" { target *-*-* } 350 }
+// { dg-error "multiple inlined namespaces" "" { target *-*-* } 0 }
// "template argument 1 is invalid"
// { dg-prune-output "tuple:993" }