diff mbox

[C++,RFC,/] Again about PR 70202

Message ID 575A1B49.1040702@oracle.com
State New
Headers show

Commit Message

Paolo Carlini June 10, 2016, 1:43 a.m. UTC
... and this version passes testing. For real.

Paolo.

////////////////////////////

Comments

Jason Merrill June 10, 2016, 8:08 p.m. UTC | #1
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
Paolo Carlini June 10, 2016, 8:15 p.m. UTC | #2
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.
Paolo Carlini June 10, 2016, 8:30 p.m. UTC | #3
.. 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.
Paolo Carlini June 10, 2016, 8:33 p.m. UTC | #4
. 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.
Paolo Carlini June 10, 2016, 8:47 p.m. UTC | #5
.. 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.
diff mbox

Patch

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;