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))
--- /dev/null
+// 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" }
+ ;
+}