From 26144dde3b68a331a8db86a9c8eaaa63d572bce9 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 14 Apr 2016 22:23:05 -0400 Subject: [PATCH] re PR c++/70528 (bogus error: constructor required before non-static data member) PR c++/70528 * class.c (type_has_constexpr_default_constructor): Return true for an implicitly declared constructor. From-SVN: r235002 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/class.c | 8 +++++--- gcc/testsuite/g++.dg/cpp0x/constexpr-ctor12.C | 1 + .../g++.dg/cpp0x/constexpr-default-ctor.C | 4 ++-- gcc/testsuite/g++.dg/cpp0x/constexpr-ice6.C | 2 +- gcc/testsuite/g++.dg/cpp0x/inh-ctor19.C | 2 +- gcc/testsuite/g++.dg/cpp0x/pr70528.C | 16 ++++++++++++++++ 7 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr70528.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6384ab89037..12900d3cd45 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2016-04-14 Jason Merrill + PR c++/70528 + * class.c (type_has_constexpr_default_constructor): Return true + for an implicitly declared constructor. + PR c++/70622 * parser.c (cp_parser_init_declarator): Add auto_result parm. (cp_parser_simple_declaration): Pass it. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 02a992fa518..e6d5bb0fe9c 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3346,7 +3346,6 @@ add_implicitly_declared_members (tree t, tree* access_decls, CLASSTYPE_LAZY_DEFAULT_CTOR (t) = 1; if (cxx_dialect >= cxx11) TYPE_HAS_CONSTEXPR_CTOR (t) - /* This might force the declaration. */ = type_has_constexpr_default_constructor (t); } @@ -5349,8 +5348,11 @@ type_has_constexpr_default_constructor (tree t) { if (!TYPE_HAS_COMPLEX_DFLT (t)) return trivial_default_constructor_is_constexpr (t); - /* Non-trivial, we need to check subobject constructors. */ - lazily_declare_fn (sfk_constructor, t); + /* Assume it's constexpr to avoid unnecessary instantiation; if the + definition would have made the class non-literal, it will still be + non-literal because of the base or member in question, and that + gives a better diagnostic. */ + return true; } fns = locate_ctor (t); return (fns && DECL_DECLARED_CONSTEXPR_P (fns)); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor12.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor12.C index 45e1ed27fae..42ca30a38ce 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor12.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor12.C @@ -3,6 +3,7 @@ template struct C { + C() = default; constexpr C(const Tp& r) { } }; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-default-ctor.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-default-ctor.C index a67505d749b..8d352d0bb99 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-default-ctor.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-default-ctor.C @@ -7,6 +7,6 @@ struct A { struct B: A { }; constexpr int f(B b) { return b.i; } -struct C { C(); }; // { dg-message "calls non-constexpr" } -struct D: C { }; // { dg-message "no constexpr constructor" } +struct C { C(); }; // { dg-message "" } +struct D: C { }; // { dg-message "" } constexpr int g(D d) { return 42; } // { dg-error "invalid type" } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ice6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice6.C index 30e0a643bcb..bf95b2443c7 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ice6.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice6.C @@ -6,6 +6,6 @@ struct A A(int); }; -struct B : A {}; // { dg-error "no matching" } +struct B : A {}; // { dg-message "" } constexpr int foo(B) { return 0; } // { dg-error "invalid type" } diff --git a/gcc/testsuite/g++.dg/cpp0x/inh-ctor19.C b/gcc/testsuite/g++.dg/cpp0x/inh-ctor19.C index 7a22f8830ec..7e2d58b422e 100644 --- a/gcc/testsuite/g++.dg/cpp0x/inh-ctor19.C +++ b/gcc/testsuite/g++.dg/cpp0x/inh-ctor19.C @@ -8,7 +8,7 @@ struct A struct B : A { - using A::A; // { dg-error "inherited" } + using A::A; }; constexpr B b; // { dg-error "literal" } diff --git a/gcc/testsuite/g++.dg/cpp0x/pr70528.C b/gcc/testsuite/g++.dg/cpp0x/pr70528.C new file mode 100644 index 00000000000..af1c84e1e94 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr70528.C @@ -0,0 +1,16 @@ +// PR c++/70258 +// { dg-do compile { target c++11 } } + +template +struct H +{ + template + H (); +}; + +struct J { + struct K { + int First = 0; + }; + H FunctionMDInfo; +}; -- 2.30.2