From 639475f047006ae1008d6dedaabdb56aba03a731 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 3 Mar 2016 17:43:03 -0500 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 5 +++-- gcc/testsuite/g++.dg/cpp0x/constexpr-empty11.C | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-empty11.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f1d51cfa481..f2c9cd25c1b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-03-03 Jason Merrill + + PR c++/67364 + * constexpr.c (cxx_eval_component_reference): Just return an empty + CONSTRUCTOR for an empty class. + 2016-03-01 Jason Merrill PR c++/70036 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index bcb129f22c4..5a81469b8ad 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 00000000000..7437367d6af --- /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 +struct element : Xn { + constexpr element() : Xn() { } +}; + +template +struct closure { + element member; + constexpr closure() { } +}; + +struct empty { struct {} s; }; +constexpr closure tup{}; +constexpr empty first = tup.member;