PR c++/82461 - constexpr list-initialized member
authorJason Merrill <jason@redhat.com>
Thu, 18 Jan 2018 20:02:06 +0000 (15:02 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 18 Jan 2018 20:02:06 +0000 (15:02 -0500)
* constexpr.c (potential_constant_expression_1): Check
TARGET_EXPR_DIRECT_INIT_P.

From-SVN: r256860

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

index 2de9dcb06d5949a063a4413e3f3d87bd70c0731f..2240913b0a7fe849c5eb4ce6c424cb91038c05ce 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-18  Jason Merrill  <jason@redhat.com>
+
+       PR c++/82461 - constexpr list-initialized member
+       * constexpr.c (potential_constant_expression_1): Check
+       TARGET_EXPR_DIRECT_INIT_P.
+
 2018-01-18  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/81013
index 8984613aa4169ecb41385b0a91cbdae4cbf407e3..9a548d29bbc10fce096519c7102c86fbbb89acec 100644 (file)
@@ -5726,7 +5726,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
       return RECUR (TREE_OPERAND (t, 1), want_rval);
 
     case TARGET_EXPR:
-      if (!literal_type_p (TREE_TYPE (t)))
+      if (!TARGET_EXPR_DIRECT_INIT_P (t)
+         && !literal_type_p (TREE_TYPE (t)))
        {
          if (flags & tf_error)
            {
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-list2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-list2.C
new file mode 100644 (file)
index 0000000..780a64d
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/82461
+// { dg-do compile { target c++11 } }
+
+class A {
+private:
+public:
+  constexpr A() {}
+  ~A() {}
+};
+
+class B {
+private:
+  A  a;
+public:
+  constexpr B() : a{} {}
+// works
+// constexpr B() : a() {}
+
+  ~B() {}
+};