From: Rodrigo Rivas Costa Date: Wed, 22 Dec 2010 19:23:00 +0000 (+0000) Subject: parser.c (cp_parser_unary_expression): Call pedwarn for alignof with expression. X-Git-Tag: releases/gcc-4.6.0~1658 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=711aef43312b1b8ca3f3ee4f53db27299ae9c2f4;p=thirdparty%2Fgcc.git parser.c (cp_parser_unary_expression): Call pedwarn for alignof with expression. * parser.c (cp_parser_unary_expression): Call pedwarn for alignof with expression. From-SVN: r168179 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 872cd0617cbb..62b7d8d8197c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2010-12-22 Rodrigo Rivas Costa + + * parser.c (cp_parser_unary_expression): Call pedwarn for alignof + with expression. + 2010-12-18 Nicola Pero * parser.c (cp_parser_objc_try_catch_finally_statement): Call diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 1a2d4253c778..743d774b5a35 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -5888,6 +5888,7 @@ cp_parser_pseudo_destructor_name (cp_parser* parser, unary-operator cast-expression sizeof unary-expression sizeof ( type-id ) + alignof ( type-id ) [C++0x] new-expression delete-expression @@ -5897,6 +5898,7 @@ cp_parser_pseudo_destructor_name (cp_parser* parser, __extension__ cast-expression __alignof__ unary-expression __alignof__ ( type-id ) + alignof unary-expression [C++0x] __real__ cast-expression __imag__ cast-expression && identifier @@ -5938,7 +5940,19 @@ cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p, if (TYPE_P (operand)) return cxx_sizeof_or_alignof_type (operand, op, true); else - return cxx_sizeof_or_alignof_expr (operand, op, true); + { + /* ISO C++ defines alignof only with types, not with + expressions. So pedwarn if alignof is used with a non- + type expression. However, __alignof__ is ok. */ + if (cxx_dialect >= cxx0x + && !strcmp (IDENTIFIER_POINTER (token->u.value), + "alignof")) + pedwarn (token->location, OPT_pedantic, + "ISO C++ does not allow % " + "with a non-type"); + + return cxx_sizeof_or_alignof_expr (operand, op, true); + } } case RID_NEW: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dd58aa54524a..06257d17853d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-12-22 Rodrigo Rivas Costa + + * g++.dg/cpp0x/alignof2.C: New. + 2010-12-22 Martin Jambor PR tree-optimization/45934 diff --git a/gcc/testsuite/g++.dg/cpp0x/alignof2.C b/gcc/testsuite/g++.dg/cpp0x/alignof2.C new file mode 100644 index 000000000000..7c5aad3de296 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alignof2.C @@ -0,0 +1,7 @@ +// { dg-do compile } +// { dg-options "-std=c++0x -pedantic" } +int main(void) +{ + alignof(int); //ok with a type but not with an expression + alignof(3); // { dg-warning "alignof" } +}