commit 6207dfd6bce685275831f468e9954bec71d39430
Author: Jason Merrill <jason@redhat.com>
Date: Fri Mar 4 15:40:16 2016 -0500
PR c++/67364
* constexpr.c (cxx_eval_component_reference): Further tweak.
@@ -1990,13 +1990,16 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t,
return t;
}
- if (CONSTRUCTOR_NO_IMPLICIT_ZERO (whole)
- && !is_really_empty_class (TREE_TYPE (t)))
+ /* We only create a CONSTRUCTOR for a subobject when we modify it, so empty
+ classes never get represented; throw together a value now. */
+ if (is_really_empty_class (TREE_TYPE (t)))
+ return build_constructor (TREE_TYPE (t), NULL);
+
+ if (CONSTRUCTOR_NO_IMPLICIT_ZERO (whole))
{
/* 'whole' is part of the aggregate initializer we're currently
building; if there's no initializer for this member yet, that's an
- error. But expand_aggr_init_1 doesn't bother to initialize really
- empty classes, so ignore them here, too. */
+ error. */
if (!ctx->quiet)
error ("accessing uninitialized member %qD", part);
*non_constant_p = true;
new file mode 100644
@@ -0,0 +1,27 @@
+// { dg-do compile { target c++14 } }
+
+struct A
+{
+ constexpr A(int) { }
+};
+
+struct B: A {
+ constexpr B(int i): A(i) { }
+ constexpr B(const B& b): A(b) { }
+};
+
+struct C {
+ B b;
+ constexpr C(int i): b(i) { }
+ constexpr C(const C&c): b(c.b) {}
+};
+
+constexpr int f()
+{
+ C b1{42};
+ C b2{b1};
+ b2.b;
+ return 42;
+}
+
+constexpr int i = f();