diff mbox

Add the latest C++ SD-6 additions.

Message ID 546023E6.6030207@verizon.net
State New
Headers show

Commit Message

Ed Smith-Rowland Nov. 10, 2014, 2:33 a.m. UTC
I would like to put this patch out before Stage 1 ends even if there is 
bikeshed renaming of macros in the next couple weeks as the C++ 
committee wraps up after their meeting.

The main part of this patch is a __has_cpp_attribute macro.
#if __has_cpp_attribute(foobar)
#else
#endif

In C++ we can use namespaces as well:
#if __has_cpp_attribute(gnu::foobar)
#else
#endif

I also added __has_attribute with the same sematics as an extension 
since clang has it.
I made these available to C as well as C++.

There are also two C++98 flags in SD-6 added since most compilers allow 
one to switch these features off:
__cpp_rtti, __cpp_exceptions.  These are not defined if -fno-rtti 
-fno-exceptions respectively.

Also, the macro __cpp_attribute_deprecated has been removed in favor of 
__has_cpp_attribute(deprecated).
Since __cpp_attribute_deprecated is out in the wild in the latest 
gcc-4.9 release perhaps I need to support this
even if, in an ironic twist, __cpp_attribute_deprecated is deprecated.  
Let me know.

This builds clean on x86_64-linux.

Is this OK once it passes testing?

Ed
libcpp:

2014-11-10  Edward Smith-Rowland  <3dw4rd@verizon.net>

	* include/cpplib.h (cpp_callbacks): Add has_attribute.
	* internal.h (lexer_state): Add in__has_attribute__.
	* directives.c (lex_macro_node): Prevent use of __has_attribute__
	as a macro.
	* expr.c (parse_has_attribute): New function; (eval_token): Look for
	__has_attribute__ and route to parse_has_attribute.
	* identifiers.c (_cpp_init_hashtable): Initialize n__has_attribute__.
	* pch.c (cpp_read_state): Initialize n__has_attribute__.
	* traditional.c (enum ls): Add ls_has_attribute, ls_has_attribute_close;
	(_cpp_scan_out_logical_line): Attend to __has_attribute__.


gcc/c-family:

2014-11-10  Edward Smith-Rowland  <3dw4rd@verizon.net>

	* c-cppbuiltin.c (__has_attribute, __has_cpp_attribute): New macros;
	(__cpp_rtti, __cpp_exceptions): New macros for C++98;
	(__cpp_range_based_for, __cpp_initializer_lists,
	__cpp_delegating_constructors, __cpp_nsdmi,
	__cpp_inheriting_constructors, __cpp_ref_qualifiers): New macros
	for C++11; (__cpp_attribute_deprecated): Remove in favor of
	__has_cpp_attribute.
	* c-lex.c (cb_has_attribute): New callback CPP function;
	(init_c_lex): Set has_attribute callback.


gcc/testsuite:

2014-11-10  Edward Smith-Rowland  <3dw4rd@verizon.net>

	* g++.dg/cpp1y/feat-cxx11.C: Test new feature macros for C++98
	and C++11; Test existence of __has_cpp_attribute;  Test C++11
	attributes.
	* g++.dg/cpp1y/feat-cxx11-neg.C: Ditto.
	* g++.dg/cpp1y/feat-cxx14.C: Ditto and test for C++14 attributes.
	* g++.dg/cpp1y/feat-cxx98.C: Test new feature macros for C++98.
	* g++.dg/cpp1y/feat-cxx98-neg.C: Ditto.
	* g++.dg/cpp1y/feat-neg.C: Test that __cpp_rtti, _cpp_exceptions
	will be undefined for -fno-rtti -fno-exceptions.

Comments

Jason Merrill Nov. 10, 2014, 4:45 a.m. UTC | #1
On 11/09/2014 08:33 PM, Ed Smith-Rowland wrote:
> +  //cpp_hashnode *node = 0;
> +      //node = token->val.node.node;
> +  //if (node)
> +  //  pfile->mi_ind_cmacro = node;

Remove this commented-out code?

The patch is OK.

Jason
diff mbox

Patch

Index: libcpp/include/cpplib.h
===================================================================
--- libcpp/include/cpplib.h	(revision 217269)
+++ libcpp/include/cpplib.h	(working copy)
@@ -580,6 +580,9 @@ 
      Second argument is the location of the start of the current expansion.  */
   void (*used) (cpp_reader *, source_location, cpp_hashnode *);
 
+  /* Callback to identify whether an attribute exists.  */
+  int (*has_attribute) (cpp_reader *);
+
   /* Callback that can change a user builtin into normal macro.  */
   bool (*user_builtin_macro) (cpp_reader *, cpp_hashnode *);
 };
Index: libcpp/internal.h
===================================================================
--- libcpp/internal.h	(revision 217269)
+++ libcpp/internal.h	(working copy)
@@ -261,6 +261,9 @@ 
   /* Nonzero if in a __has_include__ or __has_include_next__ statement.  */
   unsigned char in__has_include__;
 
+  /* Nonzero if in a __has_attribute__ statement.  */
+  unsigned char in__has_attribute__;
+
   /* Nonzero if prevent_expansion is true only because output is
      being discarded.  */
   unsigned char discarding_output;
@@ -284,6 +287,7 @@ 
   cpp_hashnode *n__VA_ARGS__;		/* C99 vararg macros */
   cpp_hashnode *n__has_include__;	/* __has_include__ operator */
   cpp_hashnode *n__has_include_next__;	/* __has_include_next__ operator */
+  cpp_hashnode *n__has_attribute__;	/* __has_attribute__ operator */
 };
 
 typedef struct _cpp_line_note _cpp_line_note;
Index: libcpp/directives.c
===================================================================
--- libcpp/directives.c	(revision 217269)
+++ libcpp/directives.c	(working copy)
@@ -571,6 +571,10 @@ 
 	     || node == pfile->spec_nodes.n__has_include_next__))
 	cpp_error (pfile, CPP_DL_ERROR,
 		   "\"__has_include__\" cannot be used as a macro name");
+      else if (is_def_or_undef
+	    && node == pfile->spec_nodes.n__has_attribute__)
+	cpp_error (pfile, CPP_DL_ERROR,
+		   "\"__has_attribute__\" cannot be used as a macro name");
       else if (! (node->flags & NODE_POISONED))
 	return node;
     }
Index: libcpp/expr.c
===================================================================
--- libcpp/expr.c	(revision 217269)
+++ libcpp/expr.c	(working copy)
@@ -65,6 +65,7 @@ 
 static void check_promotion (cpp_reader *, const struct op *);
 
 static cpp_num parse_has_include (cpp_reader *, enum include_type);
+static cpp_num parse_has_attribute (cpp_reader *);
 
 /* Token type abuse to create unary plus and minus operators.  */
 #define CPP_UPLUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 1))
@@ -1054,6 +1055,8 @@ 
 	return parse_has_include (pfile, IT_INCLUDE);
       else if (token->val.node.node == pfile->spec_nodes.n__has_include_next__)
 	return parse_has_include (pfile, IT_INCLUDE_NEXT);
+      else if (token->val.node.node == pfile->spec_nodes.n__has_attribute__)
+	return parse_has_attribute (pfile);
       else if (CPP_OPTION (pfile, cplusplus)
 	       && (token->val.node.node == pfile->spec_nodes.n_true
 		   || token->val.node.node == pfile->spec_nodes.n_false))
@@ -2147,3 +2150,21 @@ 
 
   return result;
 }
+
+/* Handle meeting "__has_attribute__" in a preprocessor expression.  */
+static cpp_num
+parse_has_attribute (cpp_reader *pfile)
+{
+  pfile->state.in__has_attribute__++;
+
+  cpp_num result;
+  result.unsignedp = false;
+  result.high = 0;
+  result.overflow = false;
+
+  result.low = pfile->cb.has_attribute (pfile);
+
+  pfile->state.in__has_attribute__--;
+
+  return result;
+}
Index: libcpp/identifiers.c
===================================================================
--- libcpp/identifiers.c	(revision 217269)
+++ libcpp/identifiers.c	(working copy)
@@ -72,6 +72,7 @@ 
   s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
   s->n__has_include__   = cpp_lookup (pfile, DSC("__has_include__"));
   s->n__has_include_next__ = cpp_lookup (pfile, DSC("__has_include_next__"));
+  s->n__has_attribute__   = cpp_lookup (pfile, DSC("__has_attribute__"));
 }
 
 /* Tear down the identifier hash table.  */
Index: libcpp/pch.c
===================================================================
--- libcpp/pch.c	(revision 217269)
+++ libcpp/pch.c	(working copy)
@@ -835,6 +835,7 @@ 
     s->n__VA_ARGS__     = cpp_lookup (r, DSC("__VA_ARGS__"));
     s->n__has_include__ = cpp_lookup (r, DSC("__has_include__"));
     s->n__has_include_next__ = cpp_lookup (r, DSC("__has_include_next__"));
+    s->n__has_attribute__ = cpp_lookup (r, DSC("__has_attribute__"));
   }
 
   old_state = r->state;
Index: libcpp/traditional.c
===================================================================
--- libcpp/traditional.c	(revision 217269)
+++ libcpp/traditional.c	(working copy)
@@ -76,7 +76,9 @@ 
 	 ls_predicate,		/* After the predicate, maybe paren?  */
 	 ls_answer,		/* In answer to predicate.  */
 	 ls_has_include,	/* After __has_include__.  */
-	 ls_has_include_close};	/* Looking for ')' of __has_include__.  */
+	 ls_has_include_close,	/* Looking for ')' of __has_include__.  */
+	 ls_has_attribute,	/* After __has_attribute__.  */
+	 ls_has_attribute_close}; /* Looking for ')' of __has_attribute__.  */
 
 /* Lexing TODO: Maybe handle space in escaped newlines.  Stop lex.c
    from recognizing comments and directives during its lexing pass.  */
@@ -533,6 +535,12 @@ 
 		  lex_state = ls_has_include;
 		  continue;
 		}
+	      else if (pfile->state.in_expression
+		       && node == pfile->spec_nodes.n__has_attribute__)
+		{
+		  lex_state = ls_has_attribute;
+		  continue;
+		}
 	    }
 	  break;
 
@@ -558,6 +566,8 @@ 
 		lex_state = ls_defined_close;
 	      else if (lex_state == ls_has_include)
 		lex_state = ls_has_include_close;
+	      else if (lex_state == ls_has_attribute)
+		lex_state = ls_has_attribute_close;
 	    }
 	  break;
 
@@ -596,7 +606,8 @@ 
 		    }
 		}
 	      else if (lex_state == ls_answer || lex_state == ls_defined_close
-			|| lex_state == ls_has_include_close)
+			|| lex_state == ls_has_include_close
+			|| lex_state == ls_has_attribute_close)
 		lex_state = ls_none;
 	    }
 	  break;
@@ -678,7 +689,8 @@ 
       else if (lex_state == ls_hash
 	       || lex_state == ls_predicate
 	       || lex_state == ls_defined
-	       || lex_state == ls_has_include)
+	       || lex_state == ls_has_include
+	       || lex_state == ls_has_attribute)
 	lex_state = ls_none;
 
       /* ls_answer and ls_defined_close keep going until ')'.  */
Index: gcc/c-family/c-cppbuiltin.c
===================================================================
--- gcc/c-family/c-cppbuiltin.c	(revision 217269)
+++ gcc/c-family/c-cppbuiltin.c	(working copy)
@@ -790,11 +790,16 @@ 
   c_stddef_cpp_builtins ();
 
   /* Set include test macros for all C/C++ (not for just C++11 etc.)
-     the builtins __has_include__ and __has_include_next__ are defined
+     The builtins __has_include__ and __has_include_next__ are defined
      in libcpp.  */
   cpp_define (pfile, "__has_include(STR)=__has_include__(STR)");
   cpp_define (pfile, "__has_include_next(STR)=__has_include_next__(STR)");
 
+  /* Set attribute test macros for all C/C++ (not for just C++11 etc.)
+     The builtin __has_attribute__ is defined in libcpp.  */
+  cpp_define (pfile, "__has_attribute(STR)=__has_attribute__(STR)");
+  cpp_define (pfile, "__has_cpp_attribute(STR)=__has_attribute__(STR)");
+
   if (c_dialect_cxx ())
     {
       if (flag_weak && SUPPORTS_ONE_ONLY)
@@ -806,7 +811,10 @@ 
 	cpp_define (pfile, "__DEPRECATED");
 
       if (flag_rtti)
-	cpp_define (pfile, "__GXX_RTTI");
+	{
+	  cpp_define (pfile, "__GXX_RTTI");
+	  cpp_define (pfile, "__cpp_rtti=199711");
+	}
 
       if (cxx_dialect >= cxx11)
         cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
@@ -824,13 +832,18 @@ 
 	  cpp_define (pfile, "__cpp_user_defined_literals=200809");
 	  cpp_define (pfile, "__cpp_lambdas=200907");
 	  cpp_define (pfile, "__cpp_constexpr=200704");
+	  cpp_define (pfile, "__cpp_range_based_for=200907");
 	  cpp_define (pfile, "__cpp_static_assert=200410");
 	  cpp_define (pfile, "__cpp_decltype=200707");
 	  cpp_define (pfile, "__cpp_attributes=200809");
 	  cpp_define (pfile, "__cpp_rvalue_reference=200610");
 	  cpp_define (pfile, "__cpp_variadic_templates=200704");
+	  cpp_define (pfile, "__cpp_initializer_lists=200806");
+	  cpp_define (pfile, "__cpp_delegating_constructors=200604");
+	  cpp_define (pfile, "__cpp_nsdmi=200809");
+	  cpp_define (pfile, "__cpp_inheriting_constructors=200802");
+	  cpp_define (pfile, "__cpp_ref_qualifiers=200710");
 	  cpp_define (pfile, "__cpp_alias_templates=200704");
-	  cpp_define (pfile, "__cpp_attribute_deprecated=201309");
 	}
       if (cxx_dialect > cxx11)
 	{
@@ -853,7 +866,11 @@ 
   /* Note that we define this for C as well, so that we know if
      __attribute__((cleanup)) will interface with EH.  */
   if (flag_exceptions)
-    cpp_define (pfile, "__EXCEPTIONS");
+    {
+      cpp_define (pfile, "__EXCEPTIONS");
+      if (c_dialect_cxx ())
+	cpp_define (pfile, "__cpp_exceptions=199711");
+    }
 
   /* Represents the C++ ABI version, always defined so it can be used while
      preprocessing C and assembler.  */
Index: gcc/c-family/c-lex.c
===================================================================
--- gcc/c-family/c-lex.c	(revision 217269)
+++ gcc/c-family/c-lex.c	(working copy)
@@ -37,6 +37,8 @@ 
 #include "target.h"
 #include "wide-int.h"
 
+#include "attribs.h"
+
 /* We may keep statistics about how long which files took to compile.  */
 static int header_time, body_time;
 static splay_tree file_info_tree;
@@ -62,6 +64,7 @@ 
 static void cb_def_pragma (cpp_reader *, unsigned int);
 static void cb_define (cpp_reader *, unsigned int, cpp_hashnode *);
 static void cb_undef (cpp_reader *, unsigned int, cpp_hashnode *);
+static int cb_has_attribute (cpp_reader *);
 
 void
 init_c_lex (void)
@@ -86,6 +89,7 @@ 
   cb->def_pragma = cb_def_pragma;
   cb->valid_pch = c_common_valid_pch;
   cb->read_pch = c_common_read_pch;
+  cb->has_attribute = cb_has_attribute;
 
   /* Set the debug callbacks if we can use them.  */
   if ((debug_info_level == DINFO_LEVEL_VERBOSE
@@ -283,6 +287,81 @@ 
   (*debug_hooks->undef) (SOURCE_LINE (map, loc),
 			 (const char *) NODE_NAME (node));
 }
+
+/* Callback for has_attribute.  */
+static int
+cb_has_attribute (cpp_reader *pfile)
+{
+  int result = 0;
+  bool paren = false;
+  //cpp_hashnode *node = 0;
+  tree attr_ns = NULL_TREE, attr_id = NULL_TREE, attr_name = NULL_TREE;
+  const cpp_token *token;
+
+  token = cpp_get_token (pfile);
+  if (token->type == CPP_OPEN_PAREN)
+    {
+      paren = true;
+      token = cpp_get_token (pfile);
+    }
+
+  if (token->type == CPP_NAME)
+    {
+      //node = token->val.node.node;
+      const cpp_token *nxt_token = cpp_peek_token (pfile, 0);
+      if (c_dialect_cxx() && nxt_token->type == CPP_SCOPE)
+	{
+	  nxt_token = cpp_get_token (pfile); // Eat scope.
+	  nxt_token = cpp_get_token (pfile);
+	  if (nxt_token->type == CPP_NAME)
+	    {
+	      attr_ns = get_identifier (
+			(const char *) cpp_token_as_text (pfile, token));
+	      attr_id = get_identifier (
+			(const char *) cpp_token_as_text (pfile, nxt_token));
+	      attr_name = build_tree_list (attr_ns, attr_id);
+	    }
+	  else
+	    cpp_error (pfile, CPP_DL_ERROR,
+		       "attribute identifier required after scope");
+	}
+      else
+	{
+	  attr_ns = get_identifier ("gnu");
+	  attr_id = get_identifier (
+		    (const char *) cpp_token_as_text (pfile, token));
+	  attr_name = build_tree_list (attr_ns, attr_id);
+	}
+      if (attr_name)
+	{
+	  const struct attribute_spec *attr = lookup_attribute_spec (attr_name);
+	  if (attr)
+	    {
+	      if (is_attribute_p ("noreturn", TREE_VALUE (attr_name)))
+		result = 200809;
+	      else if (is_attribute_p ("deprecated", TREE_VALUE (attr_name)))
+		result = 201309;
+	      else
+		result = 1;
+	    }
+	}
+    }
+  else
+    cpp_error (pfile, CPP_DL_ERROR,
+	       "operator \"__has_attribute__\" requires an identifier");
+
+  if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN)
+    cpp_error (pfile, CPP_DL_ERROR,
+	       "missing ')' after \"__has_attribute__\"");
+
+  /* A possible controlling macro of the form #if !__has_attribute__ ().
+     _cpp_parse_expr checks there was no other junk on the line.  */
+  //if (node)
+  //  pfile->mi_ind_cmacro = node;
+
+  return result;
+}
+
 
 /* Read a token and return its type.  Fill *VALUE with its value, if
    applicable.  Fill *CPP_FLAGS with the token's flags, if it is
Index: gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C	(revision 217269)
+++ gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C	(working copy)
@@ -1,6 +1,20 @@ 
 // { dg-do compile }
 // { dg-options "-std=gnu++11" }
 
+//  C++98 features:
+
+#ifndef __cpp_rtti
+#  error "__cpp_rtti"
+#elif  __cpp_rtti != 199711
+#  error "__cpp_rtti != 199711"
+#endif
+
+#ifndef __cpp_exceptions
+#  error "__cpp_exceptions"
+#elif  __cpp_exceptions != 199711
+#  error "__cpp_exceptions != 199711"
+#endif
+
 //  C++11 features:
 
 #ifndef __cpp_unicode_characters
@@ -39,6 +53,12 @@ 
 #  error "__cpp_constexpr != 200704"
 #endif
 
+#ifndef __cpp_range_based_for
+#  error "__cpp_range_based_for"
+#elif __cpp_range_based_for != 200907
+#  error "__cpp_range_based_for != 200907"
+#endif
+
 #ifndef __cpp_static_assert
 #  error "__cpp_static_assert"
 #elif __cpp_static_assert != 200410
@@ -69,6 +89,36 @@ 
 #  error "__cpp_variadic_templates != 200704"
 #endif
 
+#ifndef __cpp_initializer_lists
+#  error "__cpp_initializer_lists"
+#elif __cpp_initializer_lists != 200806
+#  error "__cpp_initializer_lists != 200806"
+#endif
+
+#ifndef __cpp_delegating_constructors
+#  error "__cpp_delegating_constructors"
+#elif __cpp_delegating_constructors != 200604
+#  error "__cpp_delegating_constructors != 200604"
+#endif
+
+#ifndef __cpp_nsdmi
+#  error "__cpp_nsdmi"
+#elif __cpp_nsdmi != 200809
+#  error "__cpp_nsdmi != 200809"
+#endif
+
+#ifndef __cpp_inheriting_constructors
+#  error "__cpp_inheriting_constructors"
+#elif  __cpp_inheriting_constructors!= 200802
+#  error "__cpp_inheriting_constructors != 200802"
+#endif
+
+#ifndef __cpp_ref_qualifiers
+#  error "__cpp_ref_qualifiers"
+#elif __cpp_ref_qualifiers != 200710
+#  error "__cpp_ref_qualifiers != 200710"
+#endif
+
 #ifndef __cpp_alias_templates
 #  error "__cpp_alias_templates"
 #elif __cpp_alias_templates != 200704
@@ -83,11 +133,38 @@ 
 #  error "__cpp_binary_literals != 201304"
 #endif
 
-//  Attribute checks:
+//  C++11 attributes:
 
+#ifdef __has_cpp_attribute
+#  if ! __has_cpp_attribute(noreturn)
+#    error "__has_cpp_attribute(noreturn)"
+#  elif __has_cpp_attribute(noreturn) != 200809
+#    error "__has_cpp_attribute(noreturn) != 200809"
+#  endif
+#else
+#  error "__has_cpp_attribute" // { dg-error "error" }
+#endif
+
+#ifdef __has_cpp_attribute
+//  Attribute carries_dependency not in yet.
+//#  if ! __has_cpp_attribute(carries_dependency)
+//#    error "__has_cpp_attribute(carries_dependency)"
+//#  elif __has_cpp_attribute(carries_dependency) != 200809
+//#    error "__has_cpp_attribute(carries_dependency) != 200809"
+//#  endif
+#else
+#  error "__has_cpp_attribute" // { dg-error "error" }
+#endif
+
+//  C++14 attributes:
+
 //  Attribute [[deprecated]] is allowed in C++11 as an extension (with pedwarn).
-#ifndef __cpp_attribute_deprecated
-#  error "__cpp_attribute_deprecated"
-#elif __cpp_attribute_deprecated != 201309
-#  error "__cpp_attribute_deprecated != 201309"
+#ifdef __has_cpp_attribute
+#  if ! __has_cpp_attribute(deprecated)
+#    error "__has_cpp_attribute(deprecated)"
+#  elif __has_cpp_attribute(deprecated) != 201309
+#    error "__has_cpp_attribute(deprecated) != 201309"
+#  endif
+#else
+#  error "__has_cpp_attribute" // { dg-error "error" }
 #endif
Index: gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C	(revision 217269)
+++ gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C	(working copy)
@@ -41,9 +41,12 @@ 
 #  error "__cpp_runtime_arrays" // { dg-error "error" }
 #endif
 
-//  Attribute checks:
+//  C++14 attributes:
 
 //  Attribute [[deprecated]] is allowed in C++11 as an extension (with pedwarn).
-//#ifndef __cpp_attribute_deprecated
-//#  error "__cpp_attribute_deprecated"
+//#ifdef __has_cpp_attribute
+//#  ifndef __has_cpp_attribute(deprecated)
+//#    error "__has_cpp_attribute(deprecated)"
+//#else
+//#  error "__has_cpp_attribute"
 //#endif
Index: gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C	(revision 217269)
+++ gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C	(working copy)
@@ -1,6 +1,20 @@ 
 // { dg-do compile { target c++14 } }
 // { dg-options "-I${srcdir}/g++.dg/cpp1y -I${srcdir}/g++.dg/cpp1y/testinc" }
 
+//  C++98 features:
+
+#ifndef __cpp_rtti
+#  error "__cpp_rtti"
+#elif  __cpp_rtti != 199711
+#  error "__cpp_rtti != 199711"
+#endif
+
+#ifndef __cpp_exceptions
+#  error "__cpp_exceptions"
+#elif  __cpp_exceptions != 199711
+#  error "__cpp_exceptions != 199711"
+#endif
+
 //  C++11 features:
 
 #ifndef __cpp_unicode_characters
@@ -39,6 +53,12 @@ 
 #  error "__cpp_constexpr != 200704"
 #endif
 
+#ifndef __cpp_range_based_for
+#  error "__cpp_range_based_for"
+#elif __cpp_range_based_for != 200907
+#  error "__cpp_range_based_for != 200907"
+#endif
+
 #ifndef __cpp_static_assert
 #  error "__cpp_static_assert"
 #elif __cpp_static_assert != 200410
@@ -69,6 +89,36 @@ 
 #  error "__cpp_variadic_templates != 200704"
 #endif
 
+#ifndef __cpp_initializer_lists
+#  error "__cpp_initializer_lists"
+#elif __cpp_initializer_lists != 200806
+#  error "__cpp_initializer_lists != 200806"
+#endif
+
+#ifndef __cpp_delegating_constructors
+#  error "__cpp_delegating_constructors"
+#elif __cpp_delegating_constructors != 200604
+#  error "__cpp_delegating_constructors != 200604"
+#endif
+
+#ifndef __cpp_nsdmi
+#  error "__cpp_nsdmi"
+#elif __cpp_nsdmi != 200809
+#  error "__cpp_nsdmi != 200809"
+#endif
+
+#ifndef __cpp_inheriting_constructors
+#  error "__cpp_inheriting_constructors"
+#elif  __cpp_inheriting_constructors!= 200802
+#  error "__cpp_inheriting_constructors != 200802"
+#endif
+
+#ifndef __cpp_ref_qualifiers
+#  error "__cpp_ref_qualifiers"
+#elif __cpp_ref_qualifiers != 200710
+#  error "__cpp_ref_qualifiers != 200710"
+#endif
+
 #ifndef __cpp_alias_templates
 #  error "__cpp_alias_templates"
 #elif __cpp_alias_templates != 200704
@@ -145,14 +195,41 @@ 
 #  error "__cpp_runtime_arrays != 201304"
 #endif
 
-//  Attribute checks:
+//  C++11 attributes:
 
-#ifndef __cpp_attribute_deprecated
-#  error "__cpp_attribute_deprecated"
-#elif __cpp_attribute_deprecated != 201309
-#  error "__cpp_attribute_deprecated != 201309"
+#ifdef __has_cpp_attribute
+#  if ! __has_cpp_attribute(noreturn)
+#    error "__has_cpp_attribute(noreturn)"
+#  elif __has_cpp_attribute(noreturn) != 200809
+#    error "__has_cpp_attribute(noreturn) != 200809"
+#  endif
+#else
+#  error "__has_cpp_attribute" // { dg-error "error" }
 #endif
 
+//  Attribute carries_dependency not in yet.
+//#ifdef __has_cpp_attribute
+//#  if ! __has_cpp_attribute(carries_dependency)
+//#    error "__has_cpp_attribute(carries_dependency)"
+//#  elif __has_cpp_attribute(carries_dependency) != 200809
+//#    error "__has_cpp_attribute(carries_dependency) != 200809"
+//#  endif
+//#else
+//#  error "__has_cpp_attribute"
+//#endif
+
+//  C++14 attributes:
+
+#ifdef __has_cpp_attribute
+#  if ! __has_cpp_attribute(deprecated)
+#    error "__has_cpp_attribute(deprecated)"
+#  elif __has_cpp_attribute(deprecated) != 201309
+#    error "__has_cpp_attribute(deprecated) != 201309"
+#  endif
+#else
+#  error "__has_cpp_attribute" // { dg-error "error" }
+#endif
+
 //  Include checks:
 
 //  Check for __has_include macro.
Index: gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C	(revision 217269)
+++ gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C	(working copy)
@@ -1,6 +1,20 @@ 
 // { dg-do compile { target c++98_only } }
 // { dg-options "" }
 
+//  C++98 features:
+
+#ifndef __cpp_rtti
+#  error "__cpp_rtti"
+#elif  __cpp_rtti != 199711
+#  error "__cpp_rtti != 199711"
+#endif
+
+#ifndef __cpp_exceptions
+#  error "__cpp_exceptions"
+#elif  __cpp_exceptions != 199711
+#  error "__cpp_exceptions != 199711"
+#endif
+
 //  C++14 features allowed in C++98 in non-ANSI modes:
 
 #ifndef __cpp_binary_literals
Index: gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C	(revision 217269)
+++ gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C	(working copy)
@@ -51,6 +51,26 @@ 
 #  error "__cpp_variadic_templates" // { dg-error "error" }
 #endif
 
+#ifndef __cpp_initializer_lists
+#  error "__cpp_initializer_lists" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_delegating_constructors
+#  error "__cpp_delegating_constructors" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_nsdmi
+#  error "__cpp_nsdmi" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_inheriting_constructors
+#  error "__cpp_inheriting_constructors" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_ref_qualifiers
+#  error "__cpp_ref_qualifiers" // { dg-error "error" }
+#endif
+
 #ifndef __cpp_alias_templates
 #  error "__cpp_alias_templates" // { dg-error "error" }
 #endif
@@ -95,8 +115,31 @@ 
 //#  error "__cpp_sized_deallocation"
 //#endif
 
-//  Attribute checks:
+//  C++11 attributes:
 
-#ifndef __cpp_attribute_deprecated
-#  error "__cpp_attribute_deprecated" // { dg-error "error" }
+#ifdef __has_cpp_attribute
+#  if ! __has_cpp_attribute(noreturn)
+#    error "__has_cpp_attribute(noreturn)"
+#  elif __has_cpp_attribute(noreturn) != 200809
+#    error "__has_cpp_attribute(noreturn) != 200809"
+#  endif
+#else
+#  error "__has_cpp_attribute" // { dg-error "error" }
 #endif
+
+//  Attribute carries_dependency not in yet.
+//#ifdef __has_cpp_attribute
+//#  if ! __has_cpp_attribute(carries_dependency)
+//#    error "__has_cpp_attribute(carries_dependency)"
+//#  elif __has_cpp_attribute(carries_dependency) != 200809
+//#    error "__has_cpp_attribute(carries_dependency) != 200809"
+//#  endif
+//#else
+//#  error "__has_cpp_attribute"
+//#endif
+
+//  C++14 attributes:
+
+#if ! __has_cpp_attribute(deprecated)
+#  error "__has_cpp_attribute(deprecated)" // { dg-error "error" }
+#endif
Index: gcc/testsuite/g++.dg/cpp1y/feat-neg.C
===================================================================
--- gcc/testsuite/g++.dg/cpp1y/feat-neg.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp1y/feat-neg.C	(working copy)
@@ -0,0 +1,12 @@ 
+// { dg-do compile { target c++98 } }
+// { dg-options "-fno-rtti -fno-exceptions" }
+
+//  C++98 features with explicit opt-out:
+
+#ifndef __cpp_rtti
+#  error "__cpp_rtti" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_exceptions
+#  error "__cpp_exceptions" // { dg-error "error" }
+#endif