aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2015-06-05 13:35:30 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2015-06-05 13:35:30 +0000
commitac59f9beec4e2f44bd3c04eb8f4fb9432feaea40 (patch)
tree4500de3ce0d127790dc285f5cd84d207f6202132 /gcc
parent22749d7e82c9fa8a276266b94df1807d23d478c6 (diff)
downloadgcc-ac59f9beec4e2f44bd3c04eb8f4fb9432feaea40.zip
gcc-ac59f9beec4e2f44bd3c04eb8f4fb9432feaea40.tar.gz
gcc-ac59f9beec4e2f44bd3c04eb8f4fb9432feaea40.tar.bz2
re PR c++/52595 ([DR 325] commas and non-static data member initializers don't mix)
cp/ PR c++/52595 * parser.c (cp_parser_cache_defarg): Continue looking for declarators when scanning a potential template argument list of an NSDMI. testsuite/ PR c++/52595 * g++,dg/cpp0x/nsdmi-defer5.C: Add template case. From-SVN: r224152
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/parser.c35
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/nsdmi-defer5.C3
4 files changed, 43 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 5a77b30..e845b9f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2015-06-05 Nathan Sidwell <nathan@acm.org>
+
+ PR c++/52595
+ * parser.c (cp_parser_cache_defarg): Continue looking for
+ declarators when scanning a potential template argument list of an
+ NSDMI.
+
2015-06-04 Andrew MacLeod <amacleod@redhat.com>
* call.c: Adjust includes for restructured coretypes.h.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ae9d3f0..2ea61c0 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -25388,6 +25388,7 @@ cp_parser_cache_defarg (cp_parser *parser, bool nsdmi)
the default argument; otherwise the default
argument continues. */
bool error = false;
+ cp_token *peek;
/* Set ITALP so cp_parser_parameter_declaration_list
doesn't decide to commit to this parse. */
@@ -25395,19 +25396,39 @@ cp_parser_cache_defarg (cp_parser *parser, bool nsdmi)
parser->in_template_argument_list_p = true;
cp_parser_parse_tentatively (parser);
- cp_lexer_consume_token (parser->lexer);
if (nsdmi)
{
- int ctor_dtor_or_conv_p;
- cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
- &ctor_dtor_or_conv_p,
- /*parenthesized_p=*/NULL,
- /*member_p=*/true,
- /*friend_p=*/false);
+ /* Parse declarators until we reach a non-comma or
+ somthing that cannot be an initializer.
+ Just checking whether we're looking at a single
+ declarator is insufficient. Consider:
+ int var = tuple<T,U>::x;
+ The template parameter 'U' looks exactly like a
+ declarator. */
+ do
+ {
+ int ctor_dtor_or_conv_p;
+ cp_lexer_consume_token (parser->lexer);
+ cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
+ &ctor_dtor_or_conv_p,
+ /*parenthesized_p=*/NULL,
+ /*member_p=*/true,
+ /*friend_p=*/false);
+ peek = cp_lexer_peek_token (parser->lexer);
+ if (cp_parser_error_occurred (parser))
+ break;
+ }
+ while (peek->type == CPP_COMMA);
+ /* If we met an '=' or ';' then the original comma
+ was the end of the NSDMI. Otherwise assume
+ we're still in the NSDMI. */
+ error = (peek->type != CPP_EQ
+ && peek->type != CPP_SEMICOLON);
}
else
{
+ cp_lexer_consume_token (parser->lexer);
begin_scope (sk_function_parms, NULL_TREE);
cp_parser_parameter_declaration_list (parser, &error);
pop_bindings_and_leave_scope ();
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 136c01c8..3d5ce99 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-06-05 Nathan Sidwell <nathan@acm.org>
+
+ PR c++/52595
+ * g++,dg/cpp0x/nsdmi-defer5.C: Add template case.
+
2015-06-05 Kugan Vivekanandarajah <kuganv@linaro.org>
* gcc.target/arm/neon-reload-class.c: Remove movw and movt.
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer5.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer5.C
index a83d40b..cb74d8f 100644
--- a/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer5.C
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer5.C
@@ -5,6 +5,9 @@ template<typename T, typename U>
struct tuple
{
tuple(T, U) { }
+
+ static const int x = 3;
+ int var = tuple<T,U>::x;
};
struct Y