This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++0x] pedantic warning with 'alignof(expression)'


Hi!

I've noticed that the C++0x draft does not allow to use the 'alignof'
operator with an expression, only with a type.
However, the GCC implementation allows both, because it is identical
to '__alignof__'  and it is implemented analogous to 'sizeof'.

I think that a pedantic warning is in order. The attached patch adds it.

Regards.
Rodrigo

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 906b0c3..7e544cf 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -5912,7 +5912,16 @@ 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);
+             {
+               /* Pedwarn if alignof is used with a non type expression.
+                  However __alignof__ is ok.  */
+               if (!strcmp(IDENTIFIER_POINTER (token->u.value), "alignof"))
+                 pedwarn (token->location, OPT_pedantic,
+                          "ISO C++ does not allow %<alignof%> "
+                          "with a non-type");
+
+               return cxx_sizeof_or_alignof_expr (operand, op, true);
+             }
          }

        case RID_NEW:

Changelog:

gcc/cp/

2010-11-14  Rodrigo Rivas Costa  <rodrigorivascosta@gmail.com>

	* parser.c (cp_parser_unary_expression): Call pedwarn por alignof
	with expression.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]