Message ID | AANLkTikVn3HRZE-Eubi+Oe_WraRUmYThkNaE6O3=HT0O@mail.gmail.com |
---|---|
State | New |
Headers | show |
On 11/14/2010 07:12 AM, Rodrigo Rivas wrote: > 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. Sounds good, but I think we only want this with -std=c++0x, not -std=gnu++0x; in other words, check cp_parser_allow_gnu_extensions_p (parser). Also, the patch was mangled by your mail client, and please include at least one testcase. Thanks, Jason
> Sounds good, but I think we only want this with -std=c++0x, not > -std=gnu++0x; in other words, check cp_parser_allow_gnu_extensions_p > (parser). Also, the patch was mangled by your mail client, and please > include at least one testcase. Hmm, I was doing that when I noted the following: 1. cp_parser_allow_gnu_extensions_p always returns true, as the comment say, for now. 2. -std=gnu++0x vs. -std=c++0x differ flag_no_gnu_keywords, flag_no_gnu_builtin and flag_iso only, none of them are used in parser.c. 3. Other GNU extensions with pedantic warnings use the following pattern: if (cp_parser_allow_gnu_extensions_p (parser)) { pedwarn (input_location, OPT_pedantic, "ISO C++ does not allow this or that"); /* do it the GNU way */ } Shouldn't this be done similarly? Regards. -- Rodrigo
On 12/01/2010 11:25 AM, Rodrigo Rivas wrote: > Hmm, I was doing that when I noted the following: > 1. cp_parser_allow_gnu_extensions_p always returns true, as the > comment say, for now. > 2. -std=gnu++0x vs. -std=c++0x differ flag_no_gnu_keywords, > flag_no_gnu_builtin and flag_iso only, none of them are used in > parser.c. > 3. Other GNU extensions with pedantic warnings use the following pattern: > > if (cp_parser_allow_gnu_extensions_p (parser)) > { > pedwarn (input_location, OPT_pedantic, > "ISO C++ does not allow this or that"); > /* do it the GNU way */ > } > > Shouldn't this be done similarly? Good points, let's handle this the same way. Jason
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); + } }