diff options
author | Patrick Palka <ppalka@redhat.com> | 2024-04-24 17:49:56 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2024-04-24 17:49:56 -0400 |
commit | 0844170e9ef60a8b2f6fba6786672f30ce1c2749 (patch) | |
tree | 39e99ce4ad16c8754283b51ee955ae9032c017d3 /gcc/cp | |
parent | 97a54c05b8e338e673e1f7fb72c0e23abb571c60 (diff) | |
download | gcc-0844170e9ef60a8b2f6fba6786672f30ce1c2749.zip gcc-0844170e9ef60a8b2f6fba6786672f30ce1c2749.tar.gz gcc-0844170e9ef60a8b2f6fba6786672f30ce1c2749.tar.bz2 |
c++: constexpr union member access folding [PR114709]
The object/offset canonicalization performed in cxx_fold_indirect_ref
is undesirable for union member accesses because it loses information
about the member being accessed which we may later need to diagnose an
inactive-member access. So this patch restricts the canonicalization
accordingly.
PR c++/114709
gcc/cp/ChangeLog:
* constexpr.cc (cxx_fold_indirect_ref): Restrict object/offset
canonicalization to RECORD_TYPE member accesses.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-union8.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/constexpr.cc | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 302b266..2e83d24 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -5799,6 +5799,9 @@ cxx_fold_indirect_ref (const constexpr_ctx *ctx, location_t loc, tree type, more folding opportunities. */ auto canonicalize_obj_off = [] (tree& obj, tree& off) { while (TREE_CODE (obj) == COMPONENT_REF + /* We need to preserve union member accesses so that we can + later properly diagnose accessing the wrong member. */ + && TREE_CODE (TREE_TYPE (TREE_OPERAND (obj, 0))) == RECORD_TYPE && (tree_int_cst_sign_bit (off) || integer_zerop (off))) { tree field = TREE_OPERAND (obj, 1); |