From patchwork Tue Sep 27 10:45:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 116574 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 3A415B6F75 for ; Tue, 27 Sep 2011 20:47:08 +1000 (EST) Received: (qmail 20348 invoked by alias); 27 Sep 2011 10:47:06 -0000 Received: (qmail 20340 invoked by uid 22791); 27 Sep 2011 10:47:05 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from smtp205.alice.it (HELO smtp205.alice.it) (82.57.200.101) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 27 Sep 2011 10:46:46 +0000 Received: from [192.168.1.4] (79.45.212.166) by smtp205.alice.it (8.5.124.08) id 4DE634750A7BE8E8; Tue, 27 Sep 2011 12:46:45 +0200 Message-ID: <4E81A94A.2040107@oracle.com> Date: Tue, 27 Sep 2011 12:45:30 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20110907 Thunderbird/6.0.2 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 32489 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, submitter asks us to be more accurate in some error messages about naming 'struct' vs 'class'. Turns out - IMHO the issue is a bit nitpicking - that we do have in place machinery for this, already used by cp_parser_class_head, which sets CLASSTYPE_DECLARED_CLASS appropriately. I'm simply doing the same in cp_parser_elaborated_type_specifier too, thus set the latter just before calling cp_parser_check_class_key. Tested x86_64-linux. Ok for mainline? Thanks, Paolo. //////////////////// /cp 2011-09-27 Paolo Carlini PR c++/31489 * parser.c (cp_parser_elaborated_type_specifier): For RECORD_TYPE, set CLASSTYPE_DECLARED_CLASS. /testsuite 2011-09-27 Paolo Carlini PR c++/31489 * g++.dg/parse/error40.C: New. * g++.dg/warn/incomplete1.C: Adjust. Index: testsuite/g++.dg/warn/incomplete1.C =================================================================== --- testsuite/g++.dg/warn/incomplete1.C (revision 179242) +++ testsuite/g++.dg/warn/incomplete1.C (working copy) @@ -9,7 +9,7 @@ // (But the deletion does not constitute an ill-formed program. So the // program should nevertheless compile, but it should give a warning.) -class A; // { dg-warning "forward declaration of 'struct A'" "" } +class A; // { dg-warning "forward declaration of 'class A'" "" } A *a; // { dg-warning "'a' has incomplete type" "" } Index: testsuite/g++.dg/parse/error40.C =================================================================== --- testsuite/g++.dg/parse/error40.C (revision 0) +++ testsuite/g++.dg/parse/error40.C (revision 0) @@ -0,0 +1,8 @@ +// PR c++/31489 + +class foobar; // { dg-error "'class foobar'" } + +int main() +{ + foobar * o = new foobar; // { dg-error "'class foobar'" } +} Index: cp/parser.c =================================================================== --- cp/parser.c (revision 179242) +++ cp/parser.c (working copy) @@ -13423,7 +13423,13 @@ cp_parser_elaborated_type_specifier (cp_parser* pa } if (tag_type != enum_type) - cp_parser_check_class_key (tag_type, type); + { + /* Indicate whether this class was declared as a `class' or as a + `struct'. */ + if (TREE_CODE (type) == RECORD_TYPE) + CLASSTYPE_DECLARED_CLASS (type) = (tag_type == class_type); + cp_parser_check_class_key (tag_type, type); + } /* A "<" cannot follow an elaborated type specifier. If that happens, the user was probably trying to form a template-id. */