]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* method.c (synthesized_method_walk): operator= can also be constexpr.
authorJason Merrill <jason@redhat.com>
Fri, 4 Mar 2016 01:48:33 +0000 (20:48 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 4 Mar 2016 01:48:33 +0000 (20:48 -0500)
From-SVN: r233956

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

index 2785135c8c71cf41a1aa054220eabbea5fbc9658..5f6d69a4622aca62b4371a091b72e3423c8ced3a 100644 (file)
@@ -1,5 +1,7 @@
 2016-03-03  Jason Merrill  <jason@redhat.com>
 
+       * method.c (synthesized_method_walk): operator= can also be constexpr.
+
        * pt.c (tsubst_copy_and_build) [LAMBDA_EXPR]: Get
        LAMBDA_EXPR_RETURN_TYPE from the instantiated closure.
 
index 0235e6a9c22ea3ee6feed57ac882222a4e1f4fb3..38f2a5427cc78d783e1aad1d81962918982ac511 100644 (file)
@@ -1379,9 +1379,18 @@ synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
 
   /* If that user-written default constructor would satisfy the
      requirements of a constexpr constructor (7.1.5), the
-     implicitly-defined default constructor is constexpr.  */
+     implicitly-defined default constructor is constexpr.
+
+     The implicitly-defined copy/move assignment operator is constexpr if
+      - X is a literal type, and
+      - the assignment operator selected to copy/move each direct base class
+       subobject is a constexpr function, and
+      - for each non-static data member of X that is of class type (or array
+       thereof), the assignment operator selected to copy/move that member is a
+       constexpr function.  */
   if (constexpr_p)
-    *constexpr_p = ctor_p;
+    *constexpr_p = ctor_p
+      || (assign_p && cxx_dialect >= cxx14);
 
   move_p = false;
   switch (sfk)
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-assign1.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-assign1.C
new file mode 100644 (file)
index 0000000..4583b64
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++14 } }
+
+struct A { };
+
+struct B
+{
+  A a;
+  constexpr B& operator=(const B&) = default;
+};