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++/27427: ICE with invalid template parameter


The C++ frontend ICEs on the following code snippet:

  struct A;

  template<A&> void foo();

  A a;

  void bar()
  {
      foo<a>();
  }

PR27427.cc:5: error: aggregate 'A a' has incomplete type and cannot be defined
PR27427.cc: In function 'void bar()':
PR27427.cc:9: internal compiler error: tree check: expected class 'type',
have 'exceptional' (error_mark) in convert_nontype_argument, at cp/pt.c:3583
Please submit a full bug report, [etc.]

When instantiating "foo" we try to convert "a" to something of type
"A&". This doesn't work as the type of "a" is an error_mark_node.
The patch below fixes the ICE by performing no conversion in such
cases.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and mainline?

Regards,
Volker

:ADDPATCH C++:


2006-05-05  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27427
	* pt.c (convert_nontype_argument): Return early on invalid arguments.

===================================================================
--- gcc/gcc/cp/pt.c	2006-05-04 21:49:04 +0200
+++ gcc/gcc/cp/pt.c	2006-05-04 23:10:02 +0200
@@ -3455,6 +3460,8 @@ convert_nontype_argument (tree type, tre
      convert the argument.  */
   expr = fold_non_dependent_expr (expr);
   expr_type = TREE_TYPE (expr);
+  if (expr_type == error_mark_node)
+    return error_mark_node;
 
   /* HACK: Due to double coercion, we can get a
      NOP_EXPR<REFERENCE_TYPE>(ADDR_EXPR<POINTER_TYPE> (arg)) here,
===================================================================

2006-05-05  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/27427
	* g++.dg/template/incomplete2.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/template/incomplete2.C	2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/template/incomplete2.C	2006-05-04 23:16:35 +0200
@@ -0,0 +1,13 @@
+// PR c++/27427
+// { dg-do compile }
+
+struct A;
+
+template<A&> void foo();
+
+A a;  // { dg-error "incomplete type" }
+
+void bar()
+{
+  foo<a>();  // { dg-error "no matching function" }
+}
===================================================================



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