[C++,obvious] PR 84705 ("[6/7/8/9 Regression] internal compiler error: in add_stmt, at cp/semantics.c:390")

Message ID ab3f4496-f677-0262-2494-1fa86a033beb@oracle.com
State New
Headers show
Series
  • [C++,obvious] PR 84705 ("[6/7/8/9 Regression] internal compiler error: in add_stmt, at cp/semantics.c:390")
Related show

Commit Message

Paolo Carlini Oct. 16, 2018, 6:39 p.m.
Hi,

the main issue is already fixed in trunk - we don't ICE anymore - but I 
noticed that for ill-formed code like:

     int i = static_cast<struct d>(i);

we emit a duplicate diagnostic about the incomplete type d, easy to 
avoid by returning error_mark_node from 
perform_direct_initialization_if_possible when build_special_member_call 
returns it. I think this latter tweak qualifies as obvious, per a 
comment made by Jason a while ago...

Tested x86_64-linux.

Thanks, Paolo.

//////////////////////
/cp
2018-10-16  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/84705
	* call.c (perform_direct_initialization_if_possible): Early return
	error_mark_node if build_special_member_call returns it.

/testsuite
2018-10-16  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/84705
	* g++.dg/cpp0x/pr84705.C: New.

Comments

Jason Merrill Oct. 16, 2018, 8:49 p.m. | #1
On Tue, Oct 16, 2018 at 2:39 PM Paolo Carlini <paolo.carlini@oracle.com> wrote:
> the main issue is already fixed in trunk - we don't ICE anymore - but I

> noticed that for ill-formed code like:

>

>      int i = static_cast<struct d>(i);

>

> we emit a duplicate diagnostic about the incomplete type d, easy to

> avoid by returning error_mark_node from

> perform_direct_initialization_if_possible when build_special_member_call

> returns it. I think this latter tweak qualifies as obvious, per a

> comment made by Jason a while ago...


Yes, but in this case it might be better to handle it in
build_cplus_new, to also cover other uses of that function.

Jason
Paolo Carlini Oct. 16, 2018, 9:15 p.m. | #2
Hi,

On 16/10/18 22:49, Jason Merrill wrote:
> On Tue, Oct 16, 2018 at 2:39 PM Paolo Carlini <paolo.carlini@oracle.com> wrote:

>> the main issue is already fixed in trunk - we don't ICE anymore - but I

>> noticed that for ill-formed code like:

>>

>>       int i = static_cast<struct d>(i);

>>

>> we emit a duplicate diagnostic about the incomplete type d, easy to

>> avoid by returning error_mark_node from

>> perform_direct_initialization_if_possible when build_special_member_call

>> returns it. I think this latter tweak qualifies as obvious, per a

>> comment made by Jason a while ago...

> Yes, but in this case it might be better to handle it in

> build_cplus_new, to also cover other uses of that function.


Ok... Then, I'm finishing testing the below. Thanks!

Paolo.

////////////////
Index: cp/tree.c
===================================================================
--- cp/tree.c	(revision 265200)
+++ cp/tree.c	(working copy)
@@ -646,6 +646,9 @@ build_cplus_new (tree type, tree init, tsubst_flag
   tree rval = build_aggr_init_expr (type, init);
   tree slot;
 
+  if (init == error_mark_node)
+    return error_mark_node;
+
   if (!complete_type_or_maybe_complain (type, init, complain))
     return error_mark_node;
 
Index: testsuite/g++.dg/cpp0x/pr84705.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr84705.C	(nonexistent)
+++ testsuite/g++.dg/cpp0x/pr84705.C	(working copy)
@@ -0,0 +1,13 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+int a[]{a};  // { dg-error "invalid conversion" }
+
+template<int>
+struct b {
+  __attribute__((c([] {
+    struct {
+      int a = static_cast<struct d>(a);  // { dg-error "invalid use of incomplete type" }
+    } e;
+  })));
+};
Jason Merrill Oct. 17, 2018, 3:46 p.m. | #3
OK.
On Tue, Oct 16, 2018 at 5:16 PM Paolo Carlini <paolo.carlini@oracle.com> wrote:
>

> Hi,

>

> On 16/10/18 22:49, Jason Merrill wrote:

> > On Tue, Oct 16, 2018 at 2:39 PM Paolo Carlini <paolo.carlini@oracle.com> wrote:

> >> the main issue is already fixed in trunk - we don't ICE anymore - but I

> >> noticed that for ill-formed code like:

> >>

> >>       int i = static_cast<struct d>(i);

> >>

> >> we emit a duplicate diagnostic about the incomplete type d, easy to

> >> avoid by returning error_mark_node from

> >> perform_direct_initialization_if_possible when build_special_member_call

> >> returns it. I think this latter tweak qualifies as obvious, per a

> >> comment made by Jason a while ago...

> > Yes, but in this case it might be better to handle it in

> > build_cplus_new, to also cover other uses of that function.

>

> Ok... Then, I'm finishing testing the below. Thanks!

>

> Paolo.

>

> ////////////////

>

Patch

Index: cp/call.c
===================================================================
--- cp/call.c	(revision 265200)
+++ cp/call.c	(working copy)
@@ -10995,6 +10995,8 @@  perform_direct_initialization_if_possible (tree ty
       expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
 					&args, type, LOOKUP_NORMAL, complain);
       release_tree_vector (args);
+      if (expr == error_mark_node)
+	return error_mark_node;
       return build_cplus_new (type, expr, complain);
     }
 
Index: testsuite/g++.dg/cpp0x/pr84705.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr84705.C	(nonexistent)
+++ testsuite/g++.dg/cpp0x/pr84705.C	(working copy)
@@ -0,0 +1,13 @@ 
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+int a[]{a};  // { dg-error "invalid conversion" }
+
+template<int>
+struct b {
+  __attribute__((c([] {
+    struct {
+      int a = static_cast<struct d>(a);  // { dg-error "invalid use of incomplete type" }
+    } e;
+  })));
+};