We don't bother evaluating a store to an empty class member, and we
shouldn't complain about accesses either.
Tested x86_64-pc-linux-gnu, applying to trunk and 5.
commit fd0e8f3776afa35340bcd3c555280012aa82f645
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Feb 24 17:14:41 2016 -0500
PR c++/67364
* constexpr.c (cxx_eval_component_reference): Don't complain about
unevaluated empty classes.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index d3b04b1..8d9168c 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1983,7 +1983,8 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t,
return t;
}
- if (CONSTRUCTOR_NO_IMPLICIT_ZERO (whole))
+ if (CONSTRUCTOR_NO_IMPLICIT_ZERO (whole)
+ && !is_empty_class (TREE_TYPE (part)))
{
/* 'whole' is part of the aggregate initializer we're currently
building; if there's no initializer for this member yet, that's an
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-empty10.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty10.C
new file mode 100644
index 0000000..694ed3d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty10.C
@@ -0,0 +1,17 @@
+// PR c++/67364
+// { dg-do compile { target c++11 } }
+
+template <typename Xn>
+struct element : Xn {
+ constexpr element() : Xn() { }
+};
+
+template <typename Xn>
+struct closure {
+ element<Xn> member;
+ constexpr closure() { }
+};
+
+struct empty { };
+constexpr closure<empty> tup{};
+constexpr empty first = tup.member;