PR c++/70979 - literal class and closure types
authorJason Merrill <jason@redhat.com>
Tue, 9 May 2017 20:37:51 +0000 (16:37 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 9 May 2017 20:37:51 +0000 (16:37 -0400)
* class.c (finalize_literal_type_property): Handle closures
specifically.
(explain_non_literal_class): Likewise.

From-SVN: r247814

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/g++.dg/cpp1z/constexpr-lambda15.C

index 521b7d9..3a12217 100644 (file)
@@ -1,5 +1,10 @@
 2017-05-09  Jason Merrill  <jason@redhat.com>
 
+       PR c++/70979 - literal class and closure types
+       * class.c (finalize_literal_type_property): Handle closures
+       specifically.
+       (explain_non_literal_class): Likewise.
+
        PR c++/66297, DR 1684 - literal class and constexpr member fns
        * constexpr.c (is_valid_constexpr_fn): Only complain about
        non-literal enclosing class in C++11.
index 89fa822..fc71766 100644 (file)
@@ -5752,6 +5752,8 @@ finalize_literal_type_property (tree t)
   if (cxx_dialect < cxx11
       || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
     CLASSTYPE_LITERAL_P (t) = false;
+  else if (CLASSTYPE_LITERAL_P (t) && LAMBDA_TYPE_P (t))
+    CLASSTYPE_LITERAL_P (t) = (cxx_dialect >= cxx1z);
   else if (CLASSTYPE_LITERAL_P (t) && !TYPE_HAS_TRIVIAL_DFLT (t)
           && CLASSTYPE_NON_AGGREGATE (t)
           && !TYPE_HAS_CONSTEXPR_CTOR (t))
@@ -5794,10 +5796,14 @@ explain_non_literal_class (tree t)
     return;
 
   inform (0, "%q+T is not literal because:", t);
-  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
+  if (cxx_dialect < cxx1z && LAMBDA_TYPE_P (t))
+    inform (0, "  %qT is a closure type, which is only literal in "
+           "C++1z and later", t);
+  else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
     inform (0, "  %q+T has a non-trivial destructor", t);
   else if (CLASSTYPE_NON_AGGREGATE (t)
           && !TYPE_HAS_TRIVIAL_DFLT (t)
+          && !LAMBDA_TYPE_P (t)
           && !TYPE_HAS_CONSTEXPR_CTOR (t))
     {
       inform (0, "  %q+T is not an aggregate, does not have a trivial "
index 7e05481..358d4aa 100644 (file)
@@ -1,9 +1,9 @@
 // PR c++/79461
-// { dg-options -std=c++1z }
+// { dg-do compile { target c++14 } }
 
 struct S {
   constexpr S(int i) {
-    auto f = [i]{};
+    auto f = [i]{};            // { dg-error "literal" "" { target c++14_only } }
   }
 };
 int main() {}