+2007-10-27 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/33842
+ * cxx-pretty-print.h (pp_cxx_offsetof_expression): New prototype.
+ * cxx-pretty-print.c (pp_cxx_primary_expression): Handle
+ OFFSETOF_EXPR.
+ (pp_cxx_offsetof_expression_1, pp_cxx_offsetof_expression): New
+ functions.
+ * error.c (dump_expr): Handle OFFSETOF_EXPR.
+
2007-10-26 Jason Merrill <jason@redhat.com>
PR c++/24791
GNU Extensions:
__builtin_va_arg ( assignment-expression , type-id )
+ __builtin_offsetof ( type-id, offsetof-expression )
__has_nothrow_assign ( type-id )
__has_nothrow_constructor ( type-id )
pp_cxx_va_arg_expression (pp, t);
break;
+ case OFFSETOF_EXPR:
+ pp_cxx_offsetof_expression (pp, t);
+ break;
+
default:
pp_c_primary_expression (pp_c_base (pp), t);
break;
pp_cxx_right_paren (pp);
}
+static bool
+pp_cxx_offsetof_expression_1 (cxx_pretty_printer *pp, tree t)
+{
+ switch (TREE_CODE (t))
+ {
+ case ARROW_EXPR:
+ if (TREE_CODE (TREE_OPERAND (t, 0)) == STATIC_CAST_EXPR
+ && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (t, 0))))
+ {
+ pp_cxx_type_id (pp, TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0))));
+ pp_cxx_separate_with (pp, ',');
+ return true;
+ }
+ return false;
+ case COMPONENT_REF:
+ if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
+ return false;
+ if (TREE_CODE (TREE_OPERAND (t, 0)) != ARROW_EXPR)
+ pp_cxx_dot (pp);
+ pp_cxx_expression (pp, TREE_OPERAND (t, 1));
+ return true;
+ case ARRAY_REF:
+ if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
+ return false;
+ pp_left_bracket (pp);
+ pp_cxx_expression (pp, TREE_OPERAND (t, 1));
+ pp_right_bracket (pp);
+ return true;
+ default:
+ return false;
+ }
+}
+
+void
+pp_cxx_offsetof_expression (cxx_pretty_printer *pp, tree t)
+{
+ pp_cxx_identifier (pp, "offsetof");
+ pp_cxx_left_paren (pp);
+ if (!pp_cxx_offsetof_expression_1 (pp, TREE_OPERAND (t, 0)))
+ pp_cxx_expression (pp, TREE_OPERAND (t, 0));
+ pp_cxx_right_paren (pp);
+}
+
void
pp_cxx_trait_expression (cxx_pretty_printer *pp, tree t)
{
void pp_cxx_trait_expression (cxx_pretty_printer *, tree);
void pp_cxx_typeid_expression (cxx_pretty_printer *, tree);
void pp_cxx_va_arg_expression (cxx_pretty_printer *, tree);
+void pp_cxx_offsetof_expression (cxx_pretty_printer *, tree);
void pp_cxx_delete_expression (cxx_pretty_printer *, tree);
#endif /* GCC_CXX_PRETTY_PRINT_H */
--- /dev/null
+// PR c++/33842
+// { dg-do compile }
+
+template<typename T> struct A
+{
+ A<__builtin_offsetof(T, x)>(); // { dg-error "type/value mismatch|offsetof\\(T, x\\)" }
+};
+
+template<typename T> struct B
+{
+ B<__builtin_offsetof(T, x.y)>(); // { dg-error "type/value mismatch|offsetof\\(T, x.y\\)" }
+};
+
+template<typename T> struct C
+{
+ C<__builtin_offsetof(T, x[6])>(); // { dg-error "type/value mismatch|offsetof\\(T, x\\\[6\\\]\\)" }
+};
+
+template<typename T> struct D
+{
+ D<__builtin_offsetof(T, x.y[6].z)>(); // { dg-error "type/value mismatch|offsetof\\(T, x.y\\\[6\\\].z\\)" }
+};
+
+struct E { int x; };
+
+template<typename T> struct F
+{
+ F<__builtin_offsetof(E, x)>(); // { dg-error "type/value mismatch|offsetof\\(E, x\\)" }
+};