From: Jason Merrill Date: Tue, 9 May 2017 20:37:51 +0000 (-0400) Subject: PR c++/70979 - literal class and closure types X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=65d7adba7ba2736bb7f11f4728c084f85f76cf86;p=gcc.git PR c++/70979 - literal class and closure types * class.c (finalize_literal_type_property): Handle closures specifically. (explain_non_literal_class): Likewise. From-SVN: r247814 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 521b7d9dade..3a12217fbf8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2017-05-09 Jason Merrill + 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. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 89fa8220150..fc717665539 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -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 " diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda15.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda15.C index 7e05481a0ed..358d4aaed8f 100644 --- a/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda15.C +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda15.C @@ -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() {}