diff mbox

[C++] PR 71440 ("ICE on invalid C++ code in instantiate_type, at cp/class.c...")

Message ID 2e8f6d3a-2a87-1238-8576-036db2c4fca4@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Aug. 2, 2017, 9:15 p.m. UTC
Hi,

by and large this issue seems already fixed in mainline, ie, we don't 
ICE anymore during error recovery, but I noticed that we try to 
prettyprint constructor and destructor as expressions and we end up with 
ugliness like:

error: taking address of constructor ‘((C<int>*)this)->*A::__ct ’

thus the below, tested x86_64-linux. Ok?

Thanks,
Paolo.

////////////////////
/cp
2017-08-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/71440
	* typeck.c (build_x_unary_op): Avoid pretty-printing constructor /
	destructor as expressions.

/testsuite
2017-08-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/71440
	* g++.dg/template/crash127.C: New.

Comments

Jason Merrill Aug. 2, 2017, 9:31 p.m. UTC | #1
OK.

On Wed, Aug 2, 2017 at 5:15 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Hi,
>
> by and large this issue seems already fixed in mainline, ie, we don't ICE
> anymore during error recovery, but I noticed that we try to prettyprint
> constructor and destructor as expressions and we end up with ugliness like:
>
> error: taking address of constructor ‘((C<int>*)this)->*A::__ct ’
>
> thus the below, tested x86_64-linux. Ok?
>
> Thanks,
> Paolo.
>
> ////////////////////
diff mbox

Patch

Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 250787)
+++ cp/typeck.c	(working copy)
@@ -5487,9 +5487,9 @@  build_x_unary_op (location_t loc, enum tree_code c
 	    {
 	      if (complain & tf_error)
 		error (DECL_CONSTRUCTOR_P (fn)
-		       ? G_("taking address of constructor %qE")
-		       : G_("taking address of destructor %qE"),
-		       xarg.get_value ());
+		       ? G_("taking address of constructor %qD")
+		       : G_("taking address of destructor %qD"),
+		       fn);
 	      return error_mark_node;
 	    }
 	}
Index: testsuite/g++.dg/template/crash127.C
===================================================================
--- testsuite/g++.dg/template/crash127.C	(revision 0)
+++ testsuite/g++.dg/template/crash127.C	(working copy)
@@ -0,0 +1,22 @@ 
+// PR c++/71440
+
+struct A 
+{
+  void f () {}
+};
+
+typedef void (A::*Ptr) ();
+
+template < Ptr > struct B {};
+
+template < class T > 
+struct C : public A
+{
+  void bar ()
+  {
+    B < &A::A > b;  // { dg-error "taking address of constructor 'A::A" "" { target c++98_only } }
+    // { dg-error "taking address of constructor 'constexpr A::A" "" { target c++11 } .-1 }
+  }
+};
+
+template class C < int >;