]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/58511 ([c++11] ICE using static const member variable in constexpr)
authorJason Merrill <jason@redhat.com>
Mon, 14 Jul 2014 05:25:37 +0000 (01:25 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 14 Jul 2014 05:25:37 +0000 (01:25 -0400)
PR c++/58511
* semantics.c (is_instantiation_of_constexpr): Return true for
defaulted functions, too.
(explain_invalid_constexpr_fn): Only use
explain_implicit_non_constexpr if !DECL_DECLARED_CONSTEXPR_P.
* method.c (explain_implicit_non_constexpr): Pass
DECL_INHERITED_CTOR_BASE to explain_implicit_non_constexpr.

From-SVN: r212507

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/constexpr-inhctor1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nsdmi3.C

index 2918318506c18c327283e2a8cd7aa97b8c180ccc..3c35c10481693201a2f50dc3c959509d694584d9 100644 (file)
@@ -1,5 +1,13 @@
 2014-07-13  Jason Merrill  <jason@redhat.com>
 
+       PR c++/58511
+       * semantics.c (is_instantiation_of_constexpr): Return true for
+       defaulted functions, too.
+       (explain_invalid_constexpr_fn): Only use
+       explain_implicit_non_constexpr if !DECL_DECLARED_CONSTEXPR_P.
+       * method.c (explain_implicit_non_constexpr): Pass
+       DECL_INHERITED_CTOR_BASE to explain_implicit_non_constexpr.
+
        PR c++/58611
        * decl.c (check_initializer): Don't finish_compound_literal
        on erroneous constexpr init.
index 4d8aac1dfbb944d3d01ef527fdb7d51242d0e449..1fa4be8d55229d7eddf4cb00cd31851f3e78a339 100644 (file)
@@ -1575,7 +1575,8 @@ explain_implicit_non_constexpr (tree decl)
   synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
                           special_function_p (decl), const_p,
                           NULL, NULL, NULL, &dummy, true,
-                          NULL_TREE, NULL_TREE);
+                          DECL_INHERITED_CTOR_BASE (decl),
+                          FUNCTION_FIRST_USER_PARMTYPE (decl));
 }
 
 /* DECL is an instantiation of an inheriting constructor template.  Deduce
index a6d941b5532cd0fa9b9c0393596e4d640a220ef9..c87764d58d46dbf2373fcbf2d24ded07b68af690 100644 (file)
@@ -3949,13 +3949,16 @@ emit_associated_thunks (tree fn)
 }
 
 /* Returns true iff FUN is an instantiation of a constexpr function
-   template.  */
+   template or a defaulted constexpr function.  */
 
 static inline bool
 is_instantiation_of_constexpr (tree fun)
 {
-  return (DECL_TEMPLOID_INSTANTIATION (fun)
-         && DECL_DECLARED_CONSTEXPR_P (DECL_TI_TEMPLATE (fun)));
+  return ((DECL_TEMPLOID_INSTANTIATION (fun)
+          && DECL_DECLARED_CONSTEXPR_P (DECL_TI_TEMPLATE (fun)))
+         || (DECL_DEFAULTED_FN (fun)
+             && DECL_DECLARED_CONSTEXPR_P (fun)));
+
 }
 
 /* Generate RTL for FN.  */
@@ -8048,7 +8051,7 @@ explain_invalid_constexpr_fn (tree fun)
   if (is_valid_constexpr_fn (fun, true))
     {
       /* Then if it's OK, the body.  */
-      if (DECL_DEFAULTED_FN (fun))
+      if (!DECL_DECLARED_CONSTEXPR_P (fun))
        explain_implicit_non_constexpr (fun);
       else
        {
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-inhctor1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-inhctor1.C
new file mode 100644 (file)
index 0000000..ee8757f
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/58511
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  constexpr A(int, int = i) {}
+  static const int i;
+};
+
+struct B : A
+{
+  using A::A;                  // { dg-error "A::i" }
+};
+
+constexpr B b(0);              // { dg-error "B::B" }
index a8e8cdf2fef75e6f89661b37153f9613cb1b7301..6ac414b7437d148652e463103eb36cf342a364ec 100644 (file)
@@ -10,9 +10,9 @@ struct B
 {
   A a1 = 1;                    // { dg-error "" }
   A a2 { 2 };
-  A a3 = { 3 };                        // { dg-error "" }
+  A a3 = { 3 };                        // { dg-error "explicit" }
 };
 
 constexpr B b;                 // { dg-error "B::B" }
 
-// { dg-message "a1. is invalid" "" { target *-*-* } 11 }
+// { dg-prune-output "uninitialized member" }