parser.c (cp_lexer_next_token_is_decl_specifier_keyword): Note that auto is either...
authorDouglas Gregor <doug.gregor@gmail.com>
Sat, 1 Mar 2008 21:39:38 +0000 (21:39 +0000)
committerDoug Gregor <dgregor@gcc.gnu.org>
Sat, 1 Mar 2008 21:39:38 +0000 (21:39 +0000)
2008-03-01  Douglas Gregor  <doug.gregor@gmail.com>

* parser.c (cp_lexer_next_token_is_decl_specifier_keyword): Note
that auto is either a storage class or a simple type specifier,
depending on the dialect.
(cp_parser_decl_specifier_seq): Complain about `auto' as a storage
specifier in C++98 mode, error in C++0x mode (since we don't
support auto as a type specifier, yet).
(cp_parser_storage_class_specifier_opt): Don't treat `auto' as a
storage specifier in C++0x mode.
(cp_parser_simple_type_specifier): Parse `auto' as a
simple-type-specifier, but error because we don't support it yet.

2008-03-01  Douglas Gregor  <doug.gregor@gmail.com>

* g++.dg/cpp0x/auto1.C: New.

From-SVN: r132806

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/auto1.C [new file with mode: 0644]

index 6fa120414b347ad6616ab546a981a4883e93aa47..6f612621e28a4b9ef6e92f94fbec2bba43478a49 100644 (file)
@@ -1,3 +1,16 @@
+2008-03-01  Douglas Gregor  <doug.gregor@gmail.com>
+
+       * parser.c (cp_lexer_next_token_is_decl_specifier_keyword): Note
+       that auto is either a storage class or a simple type specifier,
+       depending on the dialect.
+       (cp_parser_decl_specifier_seq): Complain about `auto' as a storage
+       specifier in C++98 mode, error in C++0x mode (since we don't
+       support auto as a type specifier, yet).
+       (cp_parser_storage_class_specifier_opt): Don't treat `auto' as a
+       storage specifier in C++0x mode.
+       (cp_parser_simple_type_specifier): Parse `auto' as a
+       simple-type-specifier, but error because we don't support it yet.
+
 2008-02-29  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        * parser.c (cp_parser_nonclass_name): New.
index 5f7ddcf35d89d5d0c012748f713b55caa3cf2132..817a0628987e9c8a91697039b4de67cd612ee4e8 100644 (file)
@@ -539,8 +539,10 @@ cp_lexer_next_token_is_decl_specifier_keyword (cp_lexer *lexer)
   token = cp_lexer_peek_token (lexer);
   switch (token->keyword) 
     {
-      /* Storage classes.  */
+      /* auto specifier: storage-class-specifier in C++,
+         simple-type-specifier in C++0x.  */
     case RID_AUTO:
+      /* Storage classes.  */
     case RID_REGISTER:
     case RID_STATIC:
     case RID_EXTERN:
@@ -8134,13 +8136,33 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
             GNU Extension:
               thread  */
        case RID_AUTO:
+          /* Consume the token.  */
+          cp_lexer_consume_token (parser->lexer);
+
+          if (cxx_dialect == cxx98) 
+            {
+              /* Complain about `auto' as a storage specifier, if
+                 we're complaining about C++0x compatibility.  */
+              warning 
+                (OPT_Wc__0x_compat, 
+                 "%<auto%> will change meaning in C++0x; please remove it");
+
+              /* Set the storage class anyway.  */
+              cp_parser_set_storage_class (parser, decl_specs, RID_AUTO);
+            }
+          else 
+            /* We do not yet support the use of `auto' as a
+               type-specifier.  */
+            error ("C++0x %<auto%> specifier not supported");
+          break;
+
        case RID_REGISTER:
        case RID_STATIC:
        case RID_EXTERN:
        case RID_MUTABLE:
          /* Consume the token.  */
          cp_lexer_consume_token (parser->lexer);
-         cp_parser_set_storage_class (parser, decl_specs, token->keyword);
+          cp_parser_set_storage_class (parser, decl_specs, token->keyword);
          break;
        case RID_THREAD:
          /* Consume the token.  */
@@ -8266,6 +8288,10 @@ cp_parser_storage_class_specifier_opt (cp_parser* parser)
   switch (cp_lexer_peek_token (parser->lexer)->keyword)
     {
     case RID_AUTO:
+      if (cxx_dialect != cxx98)
+        return NULL_TREE;
+      /* Fall through for C++98.  */
+
     case RID_REGISTER:
     case RID_STATIC:
     case RID_EXTERN:
@@ -10705,6 +10731,7 @@ cp_parser_type_specifier (cp_parser* parser,
    C++0x Extension:
 
    simple-type-specifier:
+     auto
      decltype ( expression )   
 
    GNU Extension:
@@ -10775,6 +10802,17 @@ cp_parser_simple_type_specifier (cp_parser* parser,
     case RID_VOID:
       type = void_type_node;
       break;
+      
+    case RID_AUTO:
+      if (cxx_dialect != cxx98)
+        {
+          /* Consume the token.  */
+          cp_lexer_consume_token (parser->lexer);
+          /* We do not yet support the use of `auto' as a
+             type-specifier.  */
+          error ("C++0x %<auto%> specifier not supported");
+        }
+      break;
 
     case RID_DECLTYPE:
       /* Parse the `decltype' type.  */
index 01a4e6f8c89c90bac07402264ce1c703e13837f5..05b49db777c7fd2cbd8e14fb3a845d5ea5675b3b 100644 (file)
@@ -1,3 +1,7 @@
+2008-03-01  Douglas Gregor  <doug.gregor@gmail.com>
+
+       * g++.dg/cpp0x/auto1.C: New.
+
 2008-03-01  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR fortran/34770
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto1.C b/gcc/testsuite/g++.dg/cpp0x/auto1.C
new file mode 100644 (file)
index 0000000..9e274b6
--- /dev/null
@@ -0,0 +1,8 @@
+// { dg-options "-std=c++98 -Wc++0x-compat" }
+
+// Test warning for use of auto in C++98 mode with C++0x
+// compatibility warnings
+void f()
+{
+  auto int x = 5; // { dg-warning "will change meaning" }
+}