Message ID | 575A1B49.1040702@oracle.com |
---|---|
State | New |
Headers | show |
On Thu, Jun 9, 2016 at 9:43 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> ... and this version passes testing. For real.
This seems reasonable, but I still wonder why b1 has error_mark_node
type, since it has no initializer at all.
Jason
Hi, On 10/06/2016 22:08, Jason Merrill wrote: > On Thu, Jun 9, 2016 at 9:43 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote: >> ... and this version passes testing. For real. > This seems reasonable, but I still wonder why b1 has error_mark_node > type, since it has no initializer at all. Well, we are now pondering very basic things we do, which normally work.. The type of b1 is B, which *is* an erroneous type, I'm not surprised by that. I'm not sure where we are going with this... if we don't have an error_mark_node as type, again ocp_convert will not catch it, and we are going to crash in build_simple_base_path.... ?? Thanks, Paolo.
.. the type of b1 becomes error_mark_node at the end of start_decl as an effect of start_decl_1 (which issues the incomplete type error). Paolo.
. in particular there is this comment in start_decl_1, where the type becomes error_mark_node: 5102 if (type_uses_auto (type)) 5103 error ("declaration of %q#D has no initializer", decl); 5104 else 5105 error ("aggregate %q#D has incomplete type and cannot be defined", 5106 decl); 5107 /* Change the type so that assemble_variable will give 5108 DECL an rtl we can live with: (mem (const_int 0)). */ 5109 type = TREE_TYPE (decl) = error_mark_node; I'd like to have some help about that... Thanks, Paolo.
.. if I disregard that comment, the incomplete type B gets through, gets to check_initializer (which is involved anyway even if there is no initializer in this case for b1) and somewhat comically gets to: else if (!COMPLETE_TYPE_P (type)) { error_at (DECL_SOURCE_LOCATION (decl), "%q#D has incomplete type", decl); TREE_TYPE (decl) = error_mark_node; return NULL_TREE; } thus we get a duplicate diagnostic about incompleteness and the type is turned into error_mark_node anyway ;) Paolo.
Index: cp/decl.c =================================================================== --- cp/decl.c (revision 237285) +++ cp/decl.c (working copy) @@ -6002,6 +6002,13 @@ check_initializer (tree decl, tree init, int flags tree init_code = NULL; tree core_type; + if (init && init != error_mark_node + && TREE_TYPE (init) == error_mark_node) + { + TREE_TYPE (decl) = error_mark_node; + return NULL_TREE; + } + /* Things that are going to be initialized need to have complete type. */ TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl)); Index: testsuite/g++.dg/inherit/crash6.C =================================================================== --- testsuite/g++.dg/inherit/crash6.C (revision 0) +++ testsuite/g++.dg/inherit/crash6.C (working copy) @@ -0,0 +1,10 @@ +// PR c++/70202 + +class A +{ + virtual void foo () { } +}; +class B : public A, A { }; // { dg-error "duplicate base type" } + +B b1, &b2 = b1; // { dg-error "incomplete type" } +A a = b2;