diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-01-04 21:13:14 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-01-04 21:13:14 +0100 |
commit | c9cf3863bdbd935be6b3915d39098c69a4f37740 (patch) | |
tree | ce4d45e6e90d78a30f569fe7f8701dfebf1da839 /gcc | |
parent | 066435fe10c4982780b05844793ddf287ac1d225 (diff) | |
download | gcc-c9cf3863bdbd935be6b3915d39098c69a4f37740.zip gcc-c9cf3863bdbd935be6b3915d39098c69a4f37740.tar.gz gcc-c9cf3863bdbd935be6b3915d39098c69a4f37740.tar.bz2 |
parser.c (cp_parser_simple_declaration): Diagnose function declaration among more than one init-declarators with auto...
* parser.c (cp_parser_simple_declaration): Diagnose function
declaration among more than one init-declarators with auto
specifier.
* g++.dg/cpp1y/auto-fn34.C: New test.
From-SVN: r244071
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/cp/parser.c | 29 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/auto-fn34.C | 12 |
4 files changed, 47 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1629420..1fe0c37 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2017-01-04 Jakub Jelinek <jakub@redhat.com> + * parser.c (cp_parser_simple_declaration): Diagnose function + declaration among more than one init-declarators with auto + specifier. + PR c++/71182 * parser.c (cp_lexer_previous_token): Use vec_safe_address in the assertion, as lexer->buffer may be NULL. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index b4b8f13..40e48f4 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -12723,8 +12723,17 @@ cp_parser_simple_declaration (cp_parser* parser, break; tree last_type; + bool auto_specifier_p; + /* NULL_TREE if both variable and function declaration are allowed, + error_mark_node if function declaration are not allowed and + a FUNCTION_DECL that should be diagnosed if it is followed by + variable declarations. */ + tree auto_function_declaration; last_type = NULL_TREE; + auto_specifier_p + = decl_specifiers.type && type_uses_auto (decl_specifiers.type); + auto_function_declaration = NULL_TREE; /* Keep going until we hit the `;' at the end of the simple declaration. */ @@ -12770,6 +12779,26 @@ cp_parser_simple_declaration (cp_parser* parser, if (cp_parser_error_occurred (parser)) goto done; + if (auto_specifier_p && cxx_dialect >= cxx14) + { + /* If the init-declarator-list contains more than one + init-declarator, they shall all form declarations of + variables. */ + if (auto_function_declaration == NULL_TREE) + auto_function_declaration + = TREE_CODE (decl) == FUNCTION_DECL ? decl : error_mark_node; + else if (TREE_CODE (decl) == FUNCTION_DECL + || auto_function_declaration != error_mark_node) + { + error_at (decl_specifiers.locations[ds_type_spec], + "non-variable %qD in declaration with more than one " + "declarator with placeholder type", + TREE_CODE (decl) == FUNCTION_DECL + ? decl : auto_function_declaration); + auto_function_declaration = error_mark_node; + } + } + if (auto_result) { if (last_type && last_type != error_mark_node diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 53ba248..a557264 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,7 @@ 2017-01-04 Jakub Jelinek <jakub@redhat.com> + * g++.dg/cpp1y/auto-fn34.C: New test. + PR c++/71182 * g++.dg/cpp0x/pr71182.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn34.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn34.C new file mode 100644 index 0000000..3b48f8d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn34.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++14 } } + +auto f1 (); +auto a = 5, f2 (); // { dg-error "in declaration with more than one declarator" } +auto f3 (), b = 6; // { dg-error "in declaration with more than one declarator" } +auto f4 (), f5 (), f6 (); // { dg-error "in declaration with more than one declarator" } +auto f1 () { return 3; } +auto f2 () { return 4; } +auto f3 () { return 5; } +auto f4 () { return 6; } +auto f5 () { return 7; } +auto f6 () { return 8; } |