aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2016-03-03 17:43:03 -0500
committerJason Merrill <jason@gcc.gnu.org>2016-03-03 17:43:03 -0500
commit639475f047006ae1008d6dedaabdb56aba03a731 (patch)
treeb11b35881862d9ecda50abe9c4567bd50d7ff5f5
parent2e981ba0684d3f76e27f374561db5c56b9c01e8e (diff)
downloadgcc-639475f047006ae1008d6dedaabdb56aba03a731.zip
gcc-639475f047006ae1008d6dedaabdb56aba03a731.tar.gz
gcc-639475f047006ae1008d6dedaabdb56aba03a731.tar.bz2
re PR c++/67364 ("accessing uninitialized member" error in constexpr context)
PR c++/67364 * constexpr.c (cxx_eval_component_reference): Just return an empty CONSTRUCTOR for an empty class. From-SVN: r233945
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/constexpr.c5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-empty11.C17
3 files changed, 26 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f1d51cf..f2c9cd2 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2016-03-03 Jason Merrill <jason@redhat.com>
+
+ PR c++/67364
+ * constexpr.c (cxx_eval_component_reference): Just return an empty
+ CONSTRUCTOR for an empty class.
+
2016-03-01 Jason Merrill <jason@redhat.com>
PR c++/70036
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index bcb129f..5a81469 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1988,11 +1988,12 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t,
}
if (CONSTRUCTOR_NO_IMPLICIT_ZERO (whole)
- && !is_empty_class (TREE_TYPE (part)))
+ && !is_really_empty_class (TREE_TYPE (t)))
{
/* 'whole' is part of the aggregate initializer we're currently
building; if there's no initializer for this member yet, that's an
- error. */
+ error. But expand_aggr_init_1 doesn't bother to initialize really
+ empty classes, so ignore them here, too. */
if (!ctx->quiet)
error ("accessing uninitialized member %qD", part);
*non_constant_p = true;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-empty11.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty11.C
new file mode 100644
index 0000000..7437367
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-empty11.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 { struct {} s; };
+constexpr closure<empty> tup{};
+constexpr empty first = tup.member;