Hi,

the below fixes an ICE on invalid which didn't occur in 4.6 (because we didn't produce the notes). The issue is that for this kind of test:

struct A
{
  A(int);
};

struct B : A {};

constexpr int foo(B) { return 0; }

add_implicitly_declared_members sets TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1 for B, but then, in explain_non_literal_class, the true value doesn't imply that locate_ctor actually finds the constructor, due to the nature of A.

Tested x86_64-linux. Ok?

Thanks,
Paolo.

///////////////////////
/cp
2011-11-30  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/51327
        * class.c (explain_non_literal_class): Check locate_ctor return value.

/testsuite
2011-11-30  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/51327
        * g++.dg/cpp0x/constexpr-ice4.C: New.

Index: testsuite/g++.dg/cpp0x/constexpr-ice4.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-ice4.C     (revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-ice4.C     (revision 0)
@@ -0,0 +1,11 @@
+// PR c++/51327
+// { dg-options -std=c++0x }
+
+struct A
+{
+  A(int);
+};
+
+struct B : A {};                    // { dg-message "literal|aggregate" }
+
+constexpr int foo(B) { return 0; }  // { dg-error "invalid type" }
Index: cp/class.c
===================================================================
--- cp/class.c  (revision 181858)
+++ cp/class.c  (working copy)
@@ -4859,12 +4859,14 @@ explain_non_literal_class (tree t)
           && !TYPE_HAS_TRIVIAL_DFLT (t)
           && !TYPE_HAS_CONSTEXPR_CTOR (t))
     {
+      tree ctor;
       inform (0, "  %q+T is not an aggregate, does not have a trivial "
              "default constructor, and has no constexpr constructor that "
              "is not a copy or move constructor", t);
       if (TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
-         && !type_has_user_provided_default_constructor (t))
-       explain_invalid_constexpr_fn (locate_ctor (t));
+         && !type_has_user_provided_default_constructor (t)
+         && (ctor = locate_ctor (t)))
+       explain_invalid_constexpr_fn (ctor);
     }
   else
     {

Reply via email to