From 45b44d0a8af9fe510bbacb40a7f9b0eaec9557fd Mon Sep 17 00:00:00 2001 From: dgregor Date: Sat, 1 Mar 2008 21:39:38 +0000 Subject: [PATCH] 2008-03-01 Douglas Gregor * 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 * g++.dg/cpp0x/auto1.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@132806 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 13 ++++++++++++ gcc/cp/parser.c | 42 ++++++++++++++++++++++++++++++++++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/auto1.C | 8 ++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/auto1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6fa1204..6f61262 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,16 @@ +2008-03-01 Douglas Gregor + + * 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 * parser.c (cp_parser_nonclass_name): New. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 5f7ddcf..817a062 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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, + "% 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 % 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 % specifier not supported"); + } + break; case RID_DECLTYPE: /* Parse the `decltype' type. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 01a4e6f..05b49db 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2008-03-01 Douglas Gregor + + * g++.dg/cpp0x/auto1.C: New. + 2008-03-01 Francois-Xavier Coudert 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 index 0000000..9e274b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto1.C @@ -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" } +} -- 2.7.4