mirror of
git://gcc.gnu.org/git/gcc.git
synced 2024-12-05 04:39:59 +08:00
1d260ab0e3
This patch adds checks for attempting to change the active member of a union by methods other than a member access expression. To be able to properly distinguish `*(&u.a) = ` from `u.a = `, this patch redoes the solution for c++/59950 to avoid extranneous *&; it seems that the only case that needed the workaround was when copying empty classes. This patch also ensures that constructors for a union field mark that field as the active member before entering the call itself; this ensures that modifications of the field within the constructor's body don't cause false positives (as these will not appear to be member access expressions). This means that we no longer need to start the lifetime of empty union members after the constructor body completes. As a drive-by fix, this patch also ensures that value-initialised unions are considered to have activated their initial member for the purpose of checking stores and accesses, which catches some additional mistakes pre-C++20. PR c++/101631 PR c++/102286 gcc/cp/ChangeLog: * call.cc (build_over_call): Fold more indirect refs for trivial assignment op. * class.cc (type_has_non_deleted_trivial_default_ctor): Create. * constexpr.cc (cxx_eval_call_expression): Start lifetime of union member before entering constructor. (cxx_eval_component_reference): Check against first member of value-initialised union. (cxx_eval_store_expression): Activate member for value-initialised union. Check for accessing inactive union member indirectly. * cp-tree.h (type_has_non_deleted_trivial_default_ctor): Forward declare. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/constexpr-89336-3.C: Fix union initialisation. * g++.dg/cpp1y/constexpr-union6.C: New test. * g++.dg/cpp1y/constexpr-union7.C: New test. * g++.dg/cpp2a/constexpr-union2.C: New test. * g++.dg/cpp2a/constexpr-union3.C: New test. * g++.dg/cpp2a/constexpr-union4.C: New test. * g++.dg/cpp2a/constexpr-union5.C: New test. * g++.dg/cpp2a/constexpr-union6.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com> |
||
---|---|---|
.. | ||
call.cc | ||
cfns.gperf | ||
cfns.h | ||
ChangeLog | ||
ChangeLog-1993 | ||
ChangeLog-1994 | ||
ChangeLog-1995 | ||
ChangeLog-1996 | ||
ChangeLog-1997 | ||
ChangeLog-1998 | ||
ChangeLog-1999 | ||
ChangeLog-2000 | ||
ChangeLog-2001 | ||
ChangeLog-2002 | ||
ChangeLog-2003 | ||
ChangeLog-2004 | ||
ChangeLog-2005 | ||
ChangeLog-2006 | ||
ChangeLog-2007 | ||
ChangeLog-2008 | ||
ChangeLog-2009 | ||
ChangeLog-2010 | ||
ChangeLog-2011 | ||
ChangeLog-2012 | ||
ChangeLog-2013 | ||
ChangeLog-2014 | ||
ChangeLog-2015 | ||
ChangeLog-2016 | ||
ChangeLog-2017 | ||
ChangeLog-2018 | ||
ChangeLog-2019 | ||
ChangeLog-2020 | ||
ChangeLog-2021 | ||
ChangeLog-2022 | ||
ChangeLog.ptr | ||
ChangeLog.tree-ssa | ||
class.cc | ||
config-lang.in | ||
constexpr.cc | ||
constraint.cc | ||
contracts.cc | ||
contracts.h | ||
coroutines.cc | ||
cp-gimplify.cc | ||
cp-lang.cc | ||
cp-name-hint.h | ||
cp-objcp-common.cc | ||
cp-objcp-common.h | ||
cp-trait.def | ||
cp-tree.def | ||
cp-tree.h | ||
cp-ubsan.cc | ||
cvt.cc | ||
cxx-pretty-print.cc | ||
cxx-pretty-print.h | ||
cxxapi-data.csv | ||
decl2.cc | ||
decl.cc | ||
decl.h | ||
dump.cc | ||
error.cc | ||
except.cc | ||
expr.cc | ||
friend.cc | ||
g++spec.cc | ||
gen-cxxapi-file.py | ||
init.cc | ||
lambda.cc | ||
lang-specs.h | ||
lex.cc | ||
logic.cc | ||
Make-lang.in | ||
mangle.cc | ||
mapper-client.cc | ||
mapper-client.h | ||
mapper-resolver.cc | ||
method.cc | ||
module.cc | ||
name-lookup.cc | ||
name-lookup.h | ||
operators.def | ||
optimize.cc | ||
parser.cc | ||
parser.h | ||
pt.cc | ||
ptree.cc | ||
rtti.cc | ||
search.cc | ||
semantics.cc | ||
std-name-hint.gperf | ||
std-name-hint.h | ||
tree.cc | ||
type-utils.h | ||
typeck2.cc | ||
typeck.cc | ||
vtable-class-hierarchy.cc |