This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR c++/28266: ICE on invalid default variable


Hello.

The following invalid snippet causes an ICE with the mainline:

=== cut here ===
struct A
{
  int i;
  A(int = X);
};

void foo()
{
  A().i;
}
=== cut here ===

=== error ===
[simon@texel pr28266]$ ../../head/build/gcc/cc1plus pr28266.C
pr28266.C:4: error: 'X' was not declared in this scope
 void foo()
pr28266.C:9: internal compiler error: in gimple_add_tmp_var, at gimplify.c:720
[...]
=== error ===

The attached patch fixes this problem the following way: if a default argument 
is not valid (i.e. is parsed into error_mark_node), then we act as if there 
was no default argument in the first place by setting TREE_PURPOSE(...) to 
NULL_TREE instead of error_mark_node.

Bootstrapped on i686-pc-linux-gnu.

This introduces two new failures, in g++.dg/other/new1.C (added for bug 28267, 
that is very close to that one) and in g++.dg/template/error15.C. Both test 
cases contain invalid default arguments, and we now get an extra "no matching 
function for call" error since we do as if there was no default argument; I 
have adjusted them accordingly.

Is this patch OK? If so, could someone commit it for me please?

Thanks in advance.

Best regards,
Simon

:ADDPATCH c++:
2006-09-10  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/28266
	* parser.c (cp_parser_late_parsing_default_args): If the default argument
	is not valid, do as if there was none.
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c	(revision 116799)
+++ gcc/cp/parser.c	(working copy)
@@ -16002,6 +16002,10 @@ cp_parser_late_parsing_default_args (cp_
       if (!processing_template_decl)
 	parsed_arg = check_default_argument (TREE_VALUE (parm), parsed_arg);
 
+      /* If the default argument is not valid, do as if there was none. */
+      if (parsed_arg == error_mark_node)
+	parsed_arg = NULL_TREE;
+
       TREE_PURPOSE (parm) = parsed_arg;
 
       /* Update any instantiations we've already created.  */
2006-09-10  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/28266
	* g++.dg/parse/defarg12.C: New test.
	* g++.dg/template/error15.C: Since the invalid default argument is
	"skipped", we now fail to find the function to call.
	* g++.dg/other/new1.C: Likewise.
Index: g++.dg/other/new1.C
===================================================================
--- g++.dg/other/new1.C	(revision 116799)
+++ g++.dg/other/new1.C	(working copy)
@@ -4,11 +4,11 @@
 struct A
 {
   A();
-  void* operator new(__SIZE_TYPE__, int = X);  // { dg-error "not declared" }
+  void* operator new(__SIZE_TYPE__, int = X);  // { dg-error "not declared|note:" }
   void operator delete(void*, int);
 };
 
 void foo()
 {
-  new A;
+  new A; // { dg-error "no matching function for call" }
 }
Index: g++.dg/template/error15.C
===================================================================
--- g++.dg/template/error15.C	(revision 116799)
+++ g++.dg/template/error15.C	(working copy)
@@ -11,14 +11,14 @@ protected:
     
   A<T> a; // { dg-error "" }
     
-  void f(const A<T> * a1 = &a); // { dg-error "this location" }
+  void f(const A<T> * a1 = &a); // { dg-error "this location|note:" }
     
   void g(void);
 };
 
 template <class T>
 void B<T>::g(void) {
-  f();
+  f(); // { dg-error "no matching function for call" }
 }
 
 template class B<long>;
/* PR28266 This used to ICE in gimple_add_tmp_var */
/* { dg-do "compile" } */

struct A
{ /* { dg-error "note:" } */
  int i;
  A(int = X); /* { dg-error "was not declared in this scope|note:" }*/
};

void foo()
{
  A().i; /* { dg-error "no matching function for call to" } */
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]