Commit 26144dde by Jason Merrill Committed by Jason Merrill

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
parent eab43e69
2016-04-14 Jason Merrill <jason@redhat.com>
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.
......
......@@ -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));
......
......@@ -3,6 +3,7 @@
template <typename Tp>
struct C {
C() = default;
constexpr C(const Tp& r) { }
};
......
......@@ -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" }
......@@ -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" }
......@@ -8,7 +8,7 @@ struct A
struct B : A
{
using A::A; // { dg-error "inherited" }
using A::A;
};
constexpr B b; // { dg-error "literal" }
// PR c++/70258
// { dg-do compile { target c++11 } }
template <class T>
struct H
{
template <typename A = T, typename = decltype (A())>
H ();
};
struct J {
struct K {
int First = 0;
};
H<K> FunctionMDInfo;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment