]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/60185 (ICE with invalid default parameter)
authorJason Merrill <jason@redhat.com>
Fri, 21 Feb 2014 21:53:46 +0000 (16:53 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 21 Feb 2014 21:53:46 +0000 (16:53 -0500)
PR c++/60185
* parser.c (cp_parser_default_argument): Clear
current_class_ptr/current_class_ref like tsubst_default_argument.

From-SVN: r208029

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/overload/defarg5.C
gcc/testsuite/g++.dg/template/defarg17.C [new file with mode: 0644]

index dd926daa4202519c9638330a19ef2b28d4bc78c4..ceecb8a418ad40a38dee27a71ee4a99ea66473f2 100644 (file)
@@ -1,5 +1,9 @@
 2014-02-21  Jason Merrill  <jason@redhat.com>
 
+       PR c++/60185
+       * parser.c (cp_parser_default_argument): Clear
+       current_class_ptr/current_class_ref like tsubst_default_argument.
+
        PR c++/60252
        * lambda.c (maybe_resolve_dummy): Check lambda_function rather
        than current_binding_level.
index 7bbdf90519e7232749fc4081a275c2eb460157b4..47a67c4932021cdfbf9b3cdacc356d235b58b9f4 100644 (file)
@@ -18633,8 +18633,24 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
   /* Parse the assignment-expression.  */
   if (template_parm_p)
     push_deferring_access_checks (dk_no_deferred);
+  tree saved_class_ptr = NULL_TREE;
+  tree saved_class_ref = NULL_TREE;
+  /* The "this" pointer is not valid in a default argument.  */
+  if (cfun)
+    {
+      saved_class_ptr = current_class_ptr;
+      cp_function_chain->x_current_class_ptr = NULL_TREE;
+      saved_class_ref = current_class_ref;
+      cp_function_chain->x_current_class_ref = NULL_TREE;
+    }
   default_argument
     = cp_parser_initializer (parser, &is_direct_init, &non_constant_p);
+  /* Restore the "this" pointer.  */
+  if (cfun)
+    {
+      cp_function_chain->x_current_class_ptr = saved_class_ptr;
+      cp_function_chain->x_current_class_ref = saved_class_ref;
+    }
   if (BRACE_ENCLOSED_INITIALIZER_P (default_argument))
     maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
   if (template_parm_p)
index 06ea6bf450035194db6160d47e2a90a7f2c61689..d022b0ca59e6ed31c3f913fef74a870a317c89c5 100644 (file)
@@ -2,6 +2,6 @@
 
 struct A
 {
-  int i;
-  A() { void foo(int=i); }     // { dg-error "this" }
+  int i;                       // { dg-message "" }
+  A() { void foo(int=i); }     // { dg-error "" }
 };
diff --git a/gcc/testsuite/g++.dg/template/defarg17.C b/gcc/testsuite/g++.dg/template/defarg17.C
new file mode 100644 (file)
index 0000000..38d68d4
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/60185
+
+template<int> struct A
+{
+  int i;                       // { dg-message "" }
+  A() { void foo(int=i); }     // { dg-error "" }
+};
+
+A<0> a;