diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-02-20 22:16:27 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-02-20 22:16:27 +0100 |
commit | ed4ec9ceba552e5a04458af8923a2117b87e3ee8 (patch) | |
tree | 671cba26b4ffd52b5a18bf6ad06cd4afb7becb05 /gcc/cp | |
parent | 200a8e1a38d11c112a460e026663e8301b201d85 (diff) | |
download | gcc-ed4ec9ceba552e5a04458af8923a2117b87e3ee8.zip gcc-ed4ec9ceba552e5a04458af8923a2117b87e3ee8.tar.gz gcc-ed4ec9ceba552e5a04458af8923a2117b87e3ee8.tar.bz2 |
re PR c++/89336 (internal compiler error when compiling a constexpr function)
PR c++/89336
* constexpr.c (cxx_eval_store_expression): Diagnose changing of active
union member for -std=c++17 and earlier.
* g++.dg/cpp1y/constexpr-89336-3.C: New test.
From-SVN: r269052
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 16 |
2 files changed, 20 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index dc0d4a2..fabcb1a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-02-20 Jakub Jelinek <jakub@redhat.com> + + PR c++/89336 + * constexpr.c (cxx_eval_store_expression): Diagnose changing of active + union member for -std=c++17 and earlier. + 2019-02-19 Jason Merrill <jason@redhat.com> PR c++/87513 - 'sorry' mangling PMF template-id. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index d413c6b..a9aa7d5 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -3813,8 +3813,20 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t, if (code == UNION_TYPE && CONSTRUCTOR_NELTS (*valp) && CONSTRUCTOR_ELT (*valp, 0)->index != index) - /* Changing active member. */ - vec_safe_truncate (CONSTRUCTOR_ELTS (*valp), 0); + { + if (cxx_dialect < cxx2a) + { + if (!ctx->quiet) + error_at (cp_expr_loc_or_loc (t, input_location), + "change of the active member of a union " + "from %qD to %qD", + CONSTRUCTOR_ELT (*valp, 0)->index, + index); + *non_constant_p = true; + } + /* Changing active member. */ + vec_safe_truncate (CONSTRUCTOR_ELTS (*valp), 0); + } for (idx = 0; vec_safe_iterate (CONSTRUCTOR_ELTS (*valp), idx, &cep); |