re PR c++/33842 (Broken diagnostic: 'offsetof_expr' not supported by dump_expr)

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.

	* g++.dg/template/error34.C: New test.

From-SVN: r129677
This commit is contained in:
Jakub Jelinek 2007-10-27 13:58:26 +02:00 committed by Jakub Jelinek
parent d449b45833
commit 094a5fe265
6 changed files with 97 additions and 0 deletions

View File

@ -1,3 +1,13 @@
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

View File

@ -357,6 +357,7 @@ pp_cxx_id_expression (cxx_pretty_printer *pp, tree t)
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 )
@ -421,6 +422,10 @@ pp_cxx_primary_expression (cxx_pretty_printer *pp, tree t)
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;
@ -2177,6 +2182,49 @@ pp_cxx_va_arg_expression (cxx_pretty_printer *pp, tree t)
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)
{

View File

@ -72,6 +72,7 @@ void pp_cxx_canonical_template_parameter (cxx_pretty_printer *, tree);
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 */

View File

@ -2048,6 +2048,10 @@ dump_expr (tree t, int flags)
pp_cxx_va_arg_expression (cxx_pp, t);
break;
case OFFSETOF_EXPR:
pp_cxx_offsetof_expression (cxx_pp, t);
break;
case DELETE_EXPR:
case VEC_DELETE_EXPR:
pp_cxx_delete_expression (cxx_pp, t);

View File

@ -1,3 +1,8 @@
2007-10-27 Jakub Jelinek <jakub@redhat.com>
PR c++/33842
* g++.dg/template/error34.C: New test.
2007-10-27 Uros Bizjak <ubizjak@gmail.com>
* g++.dg/tree-ssa/ivopts-1.C: Also search for "offset: 4294967292".

View File

@ -0,0 +1,29 @@
// 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\\)" }
};