[PATCH] RFC: PR78905 define _GLIBCXX_RELEASE macro

Jonathan Wakely jwakely@redhat.com
Tue Jan 17 17:25:00 GMT 2017


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.

-------------- next part --------------
commit 6518efcc098f852310ef15e7cdb563d19803051a
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jan 17 15:45:55 2017 +0000

    PR78905 define _GLIBCXX_RELEASE macro
    
    	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.

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..691716b 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -30,9 +30,12 @@
 #ifndef _GLIBCXX_CXX_CONFIG_H
 #define _GLIBCXX_CXX_CONFIG_H 1
 
-// The current version of the C++ library in compressed ISO date format.
+// The datestamp of the C++ library in compressed ISO date format.
 #define __GLIBCXX__
 
+// The major release number for the GCC release the C++ library belongs to.
+#define _GLIBCXX_RELEASE
+
 // Macros for various attributes.
 //   _GLIBCXX_PURE
 //   _GLIBCXX_CONST
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" }


More information about the Libstdc++ mailing list