From patchwork Fri Oct 12 11:33:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 191097 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 73D1A2C007F for ; Fri, 12 Oct 2012 22:33:37 +1100 (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=1350646417; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=l8hoYYHJxWG1Ujnqy4yolG5lXQw=; b=htLpdlhMzcZmLjI 89+zo/ONGbTdTz0tCD9SLtbpG/sH3CfhrKf5FxuLaexq23POUOkn95ZKDF0YGMKm 3PVIbo3AZqBhcM37L2mozDz1lgKxSXqduX64QxagPxOobqLpoGY9J2oek1BHfr5Z ufdHLWVswoVfrHPaxe0SiAXJ4BZg= 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:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Z9zl6iZ2WnPqcaMiDVgM/gob6+qzLxjbCi65zdcFjpeygK9e+iuiQbv77y8DRO oNOGOPpXA6Fw7fSHyg4hlY4N9pTdMsFw8TSGto7Ud8cFpEVr6CN8nZlgBws1JVBc 7mG2QAgL/mK2yZJyZgyTZO348RY97oYrWOKvDQb6HhyyM=; Received: (qmail 21076 invoked by alias); 12 Oct 2012 11:33:32 -0000 Received: (qmail 21066 invoked by uid 22791); 12 Oct 2012 11:33:30 -0000 X-SWARE-Spam-Status: No, hits=-8.0 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, TW_FN, TW_KF X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 12 Oct 2012 11:33:25 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q9CBXOhN013244 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 12 Oct 2012 11:33:24 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q9CBXN5h027231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 12 Oct 2012 11:33:23 GMT Received: from abhmt108.oracle.com (abhmt108.oracle.com [141.146.116.60]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q9CBXNH2012665; Fri, 12 Oct 2012 06:33:23 -0500 Received: from [192.168.1.4] (/79.25.197.163) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 12 Oct 2012 04:33:23 -0700 Message-ID: <5077FFFE.3030709@oracle.com> Date: Fri, 12 Oct 2012 13:33:18 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120825 Thunderbird/15.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 24449 X-IsSubscribed: yes 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, a pretty old and minor issue, but it seems easy to fix. When we check for wrong declarations of ::main in grokfndecl we use processing_template_decl to reject ::main as template and we end up wrongly rejecting: template class Foob { friend int main(); }; (whereas we normally accept: class Fooa { friend int main(); }; ) using the more accurate PROCESSING_REAL_TEMPLATE_DECL_P() correctly does the trick, AFAICS. Tested x86_64-linux. Thanks, Paolo. ////////////////////////// /cp 2012-10-12 Paolo Carlini PR c++/24449 * decl.c (grokfndecl): When checking for ::main declarations use PROCESSING_REAL_TEMPLATE_DECL_P(). /testsuite 2012-10-12 Paolo Carlini PR c++/24449 * g++.dg/parse/friend-main.C: New. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 192392) +++ cp/decl.c (working copy) @@ -7416,7 +7416,7 @@ grokfndecl (tree ctype, if (ctype == NULL_TREE && DECL_MAIN_P (decl)) { - if (processing_template_decl) + if (PROCESSING_REAL_TEMPLATE_DECL_P()) error ("cannot declare %<::main%> to be a template"); if (inlinep) error ("cannot declare %<::main%> to be inline"); Index: testsuite/g++.dg/parse/friend-main.C =================================================================== --- testsuite/g++.dg/parse/friend-main.C (revision 0) +++ testsuite/g++.dg/parse/friend-main.C (working copy) @@ -0,0 +1,30 @@ +// PR c++/24449 + +class Fooa +{ + friend int main(); +}; + +template class Foob +{ + friend int main(); + int i; +}; + +int main() +{ + Foob a; + a.i = 7; +} + +class Fooc +{ + template friend int main(); // { dg-error "cannot declare .::main. to be a template" } +}; + +template class Food +{ + template friend int main(); // { dg-error "cannot declare .::main. to be a template" } +}; + +template int main() {} // { dg-error "cannot declare .::main. to be a template" }