From patchwork Fri Apr 20 13:13:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 154042 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 7DF10B70B3 for ; Fri, 20 Apr 2012 23:13:25 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1335532406; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:cc:Subject:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=+6hak1i zx50uihL9+BMij78SPAc=; b=ACClWlepvDFoVnGB+nKR1P4/2iqeboYTDNoP842 eBPyGnyuePQpoGDU6GseEQw/lexnfmU6qeBLGAjRiz3shKpyj5iVo9lo9Riqgqns oBUz4Y6XIO2Ggj7wzeAXLBecgzcqSDpqW/o9rP8GW2k3M4GF5n4ndHNsKLtmkdzf D5m4= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:cc:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=UznYK9rFcf7fvG5ynNAIle8Kw5RqZM2PDvHscMXUnIUb5bMYt+vCT1MmZAxjDq WumZGqe+jAV+lJTs0ib7g5w5oJVejjcIvC+a1cLgpGe0K7VfVv5xlG5PuGZJ8wcs nDCCOv+qdh29WBaHwLGs72UESUFTIW/pJHn/tmORhgLeQ=; Received: (qmail 21867 invoked by alias); 20 Apr 2012 13:13:21 -0000 Received: (qmail 21571 invoked by uid 22791); 20 Apr 2012 13:13:19 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail1-relais-roc.national.inria.fr (HELO mail1-relais-roc.national.inria.fr) (192.134.164.82) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 20 Apr 2012 13:13:05 +0000 Received: from ip-105.net-81-220-140.rev.numericable.fr (HELO laptop-mg.local) ([81.220.140.105]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Apr 2012 15:13:04 +0200 Date: Fri, 20 Apr 2012 15:13:03 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org cc: jason@redhat.com Subject: [C++ Patch] sizeof... and parentheses Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 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 Hello, here is a patch that requires parentheses around the argument of sizeof.... I am not sure what variadic76.C tests, so I put 2 lines, with parentheses in different places. bootstrapped and regression tested (make -k check, compared to an unpatched version). Note that I can't commit. gcc/cp/ChangeLog 2012-04-20 Marc Glisse PR c++/51314 * parser.c (cp_parser_sizeof_operand): Require parentheses for sizeof... gcc/testsuite/ChangeLog 2012-04-20 Marc Glisse PR c++/51314 * g++.dg/cpp0x/vt-51314.C: New test. * g++.dg/cpp0x/variadic76.C: Fix. Index: testsuite/g++.dg/cpp0x/variadic76.C =================================================================== --- testsuite/g++.dg/cpp0x/variadic76.C (revision 186616) +++ testsuite/g++.dg/cpp0x/variadic76.C (working copy) @@ -2,11 +2,12 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } template int foo () { - return sizeof... N (); // { dg-error "cannot be used as a function" } + return sizeof... (N ()); // { dg-error "cannot be used as a function" } + return sizeof... (N) (); // { dg-error "cannot be used as a function" } } int bar () { return foo<0> (); Index: testsuite/g++.dg/cpp0x/vt-51314.C =================================================================== --- testsuite/g++.dg/cpp0x/vt-51314.C (revision 0) +++ testsuite/g++.dg/cpp0x/vt-51314.C (revision 0) @@ -0,0 +1,15 @@ +// { dg-options "-std=c++11" } +// { dg-prune-output "invalid" } + +templatestruct A{}; +templatevoid f(U...){ + A x; // { dg-error "surrounded by parentheses" } +} + + +template struct Indices; +template struct Next_increasing_indices; +template struct Next_increasing_indices > { + typedef Indices type; // { dg-error "surrounded by parentheses" } +}; + Property changes on: testsuite/g++.dg/cpp0x/vt-51314.C ___________________________________________________________________ Added: svn:eol-style + native Added: svn:keywords + Author Date Id Revision URL Index: cp/parser.c =================================================================== --- cp/parser.c (revision 186616) +++ cp/parser.c (working copy) @@ -21965,10 +21965,13 @@ cp_parser_sizeof_operand (cp_parser* par TYPENAME, /*initialized=*/0, /*attrlist=*/NULL); } } + else if (pack_expansion_p) + error_at (cp_lexer_peek_token (parser->lexer)->location, + "% argument must be surrounded by parentheses"); /* If the type-id production did not work out, then we must be looking at the unary-expression production. */ if (!expr) expr = cp_parser_unary_expression (parser, /*address_p=*/false,