From patchwork Sun Nov 14 12:12:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Rivas X-Patchwork-Id: 71112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 82BABB7123 for ; Sun, 14 Nov 2010 23:12:43 +1100 (EST) Received: (qmail 20715 invoked by alias); 14 Nov 2010 12:12:38 -0000 Received: (qmail 20704 invoked by uid 22791); 14 Nov 2010 12:12:36 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 14 Nov 2010 12:12:31 +0000 Received: by wwb17 with SMTP id 17so1810798wwb.8 for ; Sun, 14 Nov 2010 04:12:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.7.205 with SMTP id 55mr5252054wep.96.1289736748604; Sun, 14 Nov 2010 04:12:28 -0800 (PST) Received: by 10.216.235.33 with HTTP; Sun, 14 Nov 2010 04:12:28 -0800 (PST) Date: Sun, 14 Nov 2010 13:12:28 +0100 Message-ID: Subject: [C++0x] pedantic warning with 'alignof(expression)' From: Rodrigo Rivas To: gcc-patches@gcc.gnu.org, Jason Merrill Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 case RID_NEW: Changelog: gcc/cp/ 2010-11-14 Rodrigo Rivas Costa * parser.c (cp_parser_unary_expression): Call pedwarn por alignof with expression. 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 % " + "with a non-type"); + + return cxx_sizeof_or_alignof_expr (operand, op, true); + } }