]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/50209 ([C++0x] Braced-init-lists are rejected as function default arguments)
authorJason Merrill <jason@redhat.com>
Tue, 30 Aug 2011 04:30:27 +0000 (00:30 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 30 Aug 2011 04:30:27 +0000 (00:30 -0400)
PR c++/50209
Core DR 994
* parser.c (cp_parser_default_argument): Use
cp_parser_initializer_clause.
(cp_parser_late_parsing_default_args): Likewise.

From-SVN: r178275

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

index 2e0d6ab93050992c02f091c8fce9a11f9298f926..d42d89a0a8764a8d037e480934c227ab308d871c 100644 (file)
@@ -1,3 +1,11 @@
+2011-08-29  Jason Merrill  <jason@redhat.com>
+
+       PR c++/50209
+       Core DR 994
+       * parser.c (cp_parser_default_argument): Use
+       cp_parser_initializer_clause.
+       (cp_parser_late_parsing_default_args): Likewise.
+
 2011-08-26  Jason Merrill  <jason@redhat.com>
 
        Core DR 342
index 84b8c608f9552254c7cc0d81f7f6bcffee73008c..c862a7d0e8817d7c9198f7e42db74caae41ce722 100644 (file)
@@ -16535,6 +16535,7 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
   tree default_argument = NULL_TREE;
   bool saved_greater_than_is_operator_p;
   bool saved_local_variables_forbidden_p;
+  bool non_constant_p;
 
   /* Make sure that PARSER->GREATER_THAN_IS_OPERATOR_P is
      set correctly.  */
@@ -16548,7 +16549,9 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
   if (template_parm_p)
     push_deferring_access_checks (dk_no_deferred);
   default_argument
-    = cp_parser_assignment_expression (parser, /*cast_p=*/false, NULL);
+    = cp_parser_initializer_clause (parser, &non_constant_p);
+  if (BRACE_ENCLOSED_INITIALIZER_P (default_argument))
+    maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
   if (template_parm_p)
     pop_deferring_access_checks ();
   parser->greater_than_is_operator_p = saved_greater_than_is_operator_p;
@@ -20731,6 +20734,7 @@ static void
 cp_parser_late_parsing_default_args (cp_parser *parser, tree fn)
 {
   bool saved_local_variables_forbidden_p;
+  bool non_constant_p;
   tree parm, parmdecl;
 
   /* While we're parsing the default args, we might (due to the
@@ -20775,12 +20779,14 @@ cp_parser_late_parsing_default_args (cp_parser *parser, tree fn)
       start_lambda_scope (parmdecl);
 
       /* Parse the assignment-expression.  */
-      parsed_arg = cp_parser_assignment_expression (parser, /*cast_p=*/false, NULL);
+      parsed_arg = cp_parser_initializer_clause (parser, &non_constant_p);
       if (parsed_arg == error_mark_node)
        {
          cp_parser_pop_lexer (parser);
          continue;
        }
+      if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg))
+       maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
 
       if (!processing_template_decl)
        parsed_arg = check_default_argument (TREE_VALUE (parm), parsed_arg);
index 18b19adc581484ca21b561042ab65dc6b554837c..c5208afe0e06e9ec71be33f3337b26f3b1a6c2e3 100644 (file)
@@ -1,3 +1,9 @@
+2011-08-29  Jason Merrill  <jason@redhat.com>
+
+       Core DR 994
+       PR c++/50209
+       * g++.dg/cpp0x/initlist58.C: New.
+
 2011-08-29  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/50225
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist58.C b/gcc/testsuite/g++.dg/cpp0x/initlist58.C
new file mode 100644 (file)
index 0000000..dfb9f0c
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/50209
+// { dg-options -std=c++0x }
+
+struct S { int i,j; };
+
+struct A
+{
+  static void f (S = {1,2});
+};
+
+void f (S = {3,4});
+
+int main()
+{
+  A::f();
+  f();
+}