+2003-12-19 Jason Merrill <jason@redhat.com>
+
+ PR c++/13371
+ * typeck.c (build_modify_expr): Stabilize lhs if we're narrowing.
+
2003-12-18 Richard Henderson <rth@redhat.com>
* cp-tree.h (struct lang_type_header): Remove __extension__.
tree newrhs = rhs;
tree lhstype = TREE_TYPE (lhs);
tree olhstype = lhstype;
- tree olhs = lhs;
+ tree olhs = NULL_TREE;
/* Avoid duplicate error messages from operands that had errors. */
if (lhs == error_mark_node || rhs == error_mark_node)
if (lhstype != TREE_TYPE (lhs))
{
+ /* Avoid warnings converting integral types back into enums for
+ enum bit fields. */
+ if (TREE_CODE (lhstype) == INTEGER_TYPE
+ && TREE_CODE (olhstype) == ENUMERAL_TYPE)
+ {
+ if (TREE_SIDE_EFFECTS (lhs))
+ lhs = stabilize_reference (lhs);
+ olhs = lhs;
+ }
lhs = copy_node (lhs);
TREE_TYPE (lhs) = lhstype;
}
if (olhstype == TREE_TYPE (result))
return result;
- /* Avoid warnings converting integral types back into enums
- for enum bit fields. */
- if (TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
- && TREE_CODE (olhstype) == ENUMERAL_TYPE)
+ if (olhs)
{
result = build (COMPOUND_EXPR, olhstype, result, olhs);
TREE_NO_UNUSED_WARNING (result) = 1;
--- /dev/null
+// PR c++/13371
+// Bug: We were failing to properly protect the lhs on the line marked
+// "here" from multiple evaluation.
+
+// { dg-do run }
+
+extern "C" int printf (const char *, ...);
+
+enum E { E1, E2 };
+
+struct A
+{
+ E e : 8;
+ unsigned char c;
+};
+
+A ar[2];
+
+int c;
+
+int f()
+{
+ ++c;
+ printf ("f()\n");
+ return 0;
+}
+
+int main()
+{
+ ar[0].c = 0xff;
+ ar[f()].e = E1; // here
+ return (c != 1 || ar[0].c != 0xff);
+}