From bb302f97929df9b854f7f929093441da60305254 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 23 Mar 2023 15:57:39 -0400 Subject: [PATCH] c-family: -Wsequence-point and COMPONENT_REF [PR107163] To: gcc-patches@gcc.gnu.org The patch for PR91415 fixed -Wsequence-point to treat shifts and ARRAY_REF as sequenced in C++17, and COMPONENT_REF as well. But this is unnecessary for COMPONENT_REF, since the RHS is just a FIELD_DECL with no actual evaluation, and in this testcase handling COMPONENT_REF as sequenced blows up fast in a deep inheritance tree. Instead, look through it. PR c++/107163 gcc/c-family/ChangeLog: * c-common.cc (verify_tree): Don't use sequenced handling for COMPONENT_REF. gcc/testsuite/ChangeLog: * g++.dg/template/recurse5.C: New test. --- gcc/c-family/c-common.cc | 5 +++- gcc/testsuite/g++.dg/template/recurse5.C | 37 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/recurse5.C diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index bfb950e56db..07f7beac8fd 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -2154,12 +2154,15 @@ verify_tree (tree x, struct tlist **pbefore_sp, struct tlist **pno_sp, case LSHIFT_EXPR: case RSHIFT_EXPR: - case COMPONENT_REF: case ARRAY_REF: if (cxx_dialect >= cxx17) goto sequenced_binary; goto do_default; + case COMPONENT_REF: + x = TREE_OPERAND (x, 0); + goto restart; + default: do_default: /* For other expressions, simply recurse on their operands. diff --git a/gcc/testsuite/g++.dg/template/recurse5.C b/gcc/testsuite/g++.dg/template/recurse5.C new file mode 100644 index 00000000000..0354ab09f53 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/recurse5.C @@ -0,0 +1,37 @@ +// PR c++/107163 +// { dg-additional-options "-Wsequence-point" } + +struct BaseType { + int i; +}; + +template< int Seq > +class DerivedType : public DerivedType< Seq - 1 > { }; + +template<> +class DerivedType< -1 > : public BaseType { }; + +int main() { + DerivedType< 400 > d; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + d.i = 42; + return d.i; +} -- 2.31.1