diff mbox

[libcpp] SD-6 feature macros

Message ID 36199165.lqQxHJh4ud@tjmaciei-mobl4
State New
Headers show

Commit Message

Thiago Macieira Aug. 18, 2014, 9:32 p.m. UTC
Hello

The SD-6 [1] document keeps a list of built-in #defines that allow application 
and library writers know when certain language and library features have been 
implemented by the compiler. They are optional, since a compliant compiler 
must implement them all.

But they're really useful.

This patch provides the defines for current GCC 4.9. I don't see anything in 
http://gcc.gnu.org/projects/cxx1y.html that indicates newly supported features 
for trunk, so the patch should apply to both branches now.

This patch does not add the SD-6 defines to libstdc++.

[1] N3745 and 
http://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations

Comments

Thiago Macieira Sept. 1, 2014, 10:45 p.m. UTC | #1
On Monday 18 August 2014 14:32:04 Thiago Macieira wrote:
> Hello
> 
> The SD-6 [1] document keeps a list of built-in #defines that allow
> application and library writers know when certain language and library
> features have been implemented by the compiler. They are optional, since a
> compliant compiler must implement them all.
> 
> But they're really useful.
> 
> This patch provides the defines for current GCC 4.9. I don't see anything in
> http://gcc.gnu.org/projects/cxx1y.html that indicates newly supported
> features for trunk, so the patch should apply to both branches now.
> 
> This patch does not add the SD-6 defines to libstdc++.
> 
> [1] N3745 and
> http://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendati
> ons

Hello

I sent this two weeks ago. There has been no comment suggesting improvements 
required. I'm taking that as "no further changes needed, this looks good".

I don't have a Subversion account. Could someone apply the patch, please?
diff mbox

Patch

From 5cb90354d18c4edc1dcc11cf3674542409597863 Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Mon, 18 Aug 2014 11:43:36 -0700
Subject: [PATCH 1/1] 2014-08-18  Thiago Macieira <thiago.macieira@intel.com>

	* init.c (cpp_init_builtins ()): Set the SD-6 feature defines
	in C++11 and C++14 modes.
---
 libcpp/init.c | 50 ++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 8 deletions(-)

diff --git a/libcpp/init.c b/libcpp/init.c
index f10413a..1a9d046 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -485,14 +485,48 @@  cpp_init_builtins (cpp_reader *pfile, int hosted)
 
   if (CPP_OPTION (pfile, cplusplus))
     {
-      if (CPP_OPTION (pfile, lang) == CLK_CXX1Y
-	  || CPP_OPTION (pfile, lang) == CLK_GNUCXX1Y)
-	_cpp_define_builtin (pfile, "__cplusplus 201300L");
-      else if (CPP_OPTION (pfile, lang) == CLK_CXX11
-	       || CPP_OPTION (pfile, lang) == CLK_GNUCXX11)
-	_cpp_define_builtin (pfile, "__cplusplus 201103L");
-      else
-	_cpp_define_builtin (pfile, "__cplusplus 199711L");
+      switch (CPP_OPTION (pfile, lang))
+	{
+	  case CLK_GNUCXX1Y:
+	  case CLK_CXX1Y:
+	    _cpp_define_builtin (pfile, "__cpp_init_captures 201304");
+	    _cpp_define_builtin (pfile, "__cpp_decltype_auto 201304");
+	    _cpp_define_builtin (pfile, "__cpp_return_type_deduction 201304");
+	    if (CPP_OPTION (pfile, lang) == CLK_CXX1Y
+		|| CPP_OPTION (pfile, lang) == CLK_GNUCXX1Y)
+	      _cpp_define_builtin (pfile, "__cplusplus 201300L");
+	    /* fall through */
+
+	  case CLK_GNUCXX11:
+	  case CLK_CXX11:
+	    _cpp_define_builtin (pfile, "__cpp_unicode_characters 200704");
+	    _cpp_define_builtin (pfile, "__cpp_unicode_literals 200710");
+	    _cpp_define_builtin (pfile, "__cpp_unicode_literals 200710");
+	    _cpp_define_builtin (pfile, "__cpp_user_defined_literals 200809");
+	    _cpp_define_builtin (pfile, "__cpp_lambdas 200907");
+	    _cpp_define_builtin (pfile, "__cpp_static_assert 200410");
+	    _cpp_define_builtin (pfile, "__cpp_decltype 200707");
+	    _cpp_define_builtin (pfile, "__cpp_attributes 200809");
+	    _cpp_define_builtin (pfile, "__cpp_rvalue_references 200610");
+	    _cpp_define_builtin (pfile, "__cpp_variadic_templates 200704");
+	    if (CPP_OPTION (pfile, lang) == CLK_CXX11
+		|| CPP_OPTION (pfile, lang) == CLK_GNUCXX11)
+	      {
+		_cpp_define_builtin (pfile, "__cplusplus 201103L");
+		_cpp_define_builtin (pfile, "__cpp_constexpr 200704");
+	      }
+	    if (CPP_OPTION (pfile, lang) == CLK_CXX11)
+	      break;
+	    /* fall through */
+
+	  default:
+	    if (CPP_OPTION (pfile, lang) == CLK_CXX98
+		|| CPP_OPTION (pfile, lang) == CLK_GNUCXX)
+	      _cpp_define_builtin (pfile, "__cplusplus 199711L");
+	    if (CPP_OPTION (pfile, lang) == CLK_CXX98)
+	      break;
+	    _cpp_define_builtin (pfile, "__cpp_binary_literals 201304");
+	}
     }
   else if (CPP_OPTION (pfile, lang) == CLK_ASM)
     _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
-- 
1.8.4.5