diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 21c0770da9ac..76b69f571185 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2007-03-08 Volker Reichelt + + PR c++/30852 + * c-common.c (fold_offsetof_1): Handle COMPOUND_EXPR. + 2007-03-08 Alexandre Oliva * c-decl.c (grokdeclarator): Disable warnings for anonymous diff --git a/gcc/c-common.c b/gcc/c-common.c index db64da59c03f..0bcd462ddfc0 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -6443,6 +6443,12 @@ fold_offsetof_1 (tree expr, tree stop_ref) off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t); break; + case COMPOUND_EXPR: + /* Handle static members of volatile structs. */ + t = TREE_OPERAND (expr, 1); + gcc_assert (TREE_CODE (t) == VAR_DECL); + return fold_offsetof_1 (t, stop_ref); + default: gcc_unreachable (); } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 35e0f9fdfe16..38722840a8a7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2007-03-08 Volker Reichelt + PR c++/30852 + * semantics.c (finish_offsetof): Handle COMPOUND_EXPR. + PR c++/30534 * pt.c (any_template_arguments_need_structural_equality_p): Robustify. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index c21fd2cef9e7..30f4214e5dbd 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2933,7 +2933,8 @@ finish_offsetof (tree expr) || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE || TREE_CODE (TREE_TYPE (expr)) == UNKNOWN_TYPE) { - if (TREE_CODE (expr) == COMPONENT_REF) + if (TREE_CODE (expr) == COMPONENT_REF + || TREE_CODE (expr) == COMPOUND_EXPR) expr = TREE_OPERAND (expr, 1); error ("cannot apply % to member function %qD", expr); return error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 28c386f06d74..81dd95db41bd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2007-03-08 Volker Reichelt + PR c++/30852 + * g++.dg/ext/offsetof1.C: Add cases with volatile. + PR c++/30534 * g++.dg/template/arg5.C: New test. diff --git a/gcc/testsuite/g++.dg/ext/offsetof1.C b/gcc/testsuite/g++.dg/ext/offsetof1.C index 123a9e3efeb4..1468c0a7c068 100644 --- a/gcc/testsuite/g++.dg/ext/offsetof1.C +++ b/gcc/testsuite/g++.dg/ext/offsetof1.C @@ -8,8 +8,10 @@ struct bar { }; int a = __builtin_offsetof(bar, foo); // { dg-error "static data member" } +int av = __builtin_offsetof(volatile bar, foo); // { dg-error "static data member" } int b = __builtin_offsetof(bar, baz); // { dg-error "member function" } int b0 = __builtin_offsetof(bar, baz[0]); // { dg-error "function" } +int bv0 = __builtin_offsetof(volatile bar, baz[0]); // { dg-error "function" } int c = __builtin_offsetof(bar, ~bar); // { dg-error "member function" } typedef int I;