aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fold-const.cc7
-rw-r--r--gcc/testsuite/g++.dg/warn/Wduplicated-cond2.C29
2 files changed, 34 insertions, 2 deletions
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 39a5a52..b647e53 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -3357,8 +3357,11 @@ operand_compare::operand_equal_p (const_tree arg0, const_tree arg1,
tree field0 = TREE_OPERAND (arg0, 1);
tree field1 = TREE_OPERAND (arg1, 1);
- if (!operand_equal_p (DECL_FIELD_OFFSET (field0),
- DECL_FIELD_OFFSET (field1), flags)
+ /* Non-FIELD_DECL operands can appear in C++ templates. */
+ if (TREE_CODE (field0) != FIELD_DECL
+ || TREE_CODE (field1) != FIELD_DECL
+ || !operand_equal_p (DECL_FIELD_OFFSET (field0),
+ DECL_FIELD_OFFSET (field1), flags)
|| !operand_equal_p (DECL_FIELD_BIT_OFFSET (field0),
DECL_FIELD_BIT_OFFSET (field1),
flags))
diff --git a/gcc/testsuite/g++.dg/warn/Wduplicated-cond2.C b/gcc/testsuite/g++.dg/warn/Wduplicated-cond2.C
new file mode 100644
index 0000000..c977389
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wduplicated-cond2.C
@@ -0,0 +1,29 @@
+// PR c++/105035
+// { dg-do compile }
+// { dg-options "-Wduplicated-cond" }
+
+class A {
+ struct B { int c; int f; } e;
+ template <typename> void foo ();
+ void bar ();
+};
+
+template <typename> void
+A::foo ()
+{
+ int g;
+ if (&g == &e.c)
+ ;
+ else if (&g == &e.f)
+ ;
+}
+
+void
+A::bar ()
+{
+ int g;
+ if (&g == &e.c) // { dg-message "previously used here" }
+ ;
+ else if (&g == &e.c) // { dg-warning "duplicated 'if' condition" }
+ ;
+}