From patchwork Thu Dec 15 17:24:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 131710 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 D58611007D6 for ; Fri, 16 Dec 2011 04:25:24 +1100 (EST) Received: (qmail 6812 invoked by alias); 15 Dec 2011 17:25:22 -0000 Received: (qmail 6800 invoked by uid 22791); 15 Dec 2011 17:25:21 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 15 Dec 2011 17:24:52 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pBFHOqU8016647 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 15 Dec 2011 12:24:52 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pBFHOoUw031208 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 15 Dec 2011 12:24:51 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id pBFHOoHJ004871; Thu, 15 Dec 2011 18:24:50 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id pBFHOoce004869; Thu, 15 Dec 2011 18:24:50 +0100 Date: Thu, 15 Dec 2011 18:24:50 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix ICE with initialized static volatile member (PR c++/51463) Message-ID: <20111215172450.GP1957@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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! The problem with this invalid testcase is that we first parse the initializer taking into account the static storage class (i.e. pass it as a normal static data member initializer), but later on in grokdeclarator with error on static volatile being used together and clear static because of it, and later on we attempt to use the initializer as NSDMI, which ICEs. grokdeclarator doesn't seem to see the initializer, but if DECL_INITIAL is set to error_mark_node, it will be ignored. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-12-15 Jakub Jelinek PR c++/51463 * decl.c (grokdeclarator): Set DECL_INITIAL of decl to error_mark_node to disallow NSDMI if declspecs->storage_class is sc_static. * parser.c (cp_parser_late_parse_one_default_arg): Return early if default_arg is error_mark_node. * g++.dg/cpp0x/pr51463.C: New test. Jakub --- gcc/cp/decl.c.jj 2011-12-08 16:36:49.000000000 +0100 +++ gcc/cp/decl.c 2011-12-14 17:27:32.144152053 +0100 @@ -10214,9 +10214,17 @@ grokdeclarator (const cp_declarator *dec } if (initialized) - /* An attempt is being made to initialize a non-static - member. This is new in C++11. */ - maybe_warn_cpp0x (CPP0X_NSDMI); + { + /* An attempt is being made to initialize a non-static + member. This is new in C++11. */ + maybe_warn_cpp0x (CPP0X_NSDMI); + + /* If this has been parsed with static storage class, but + errors forced staticp to be cleared, ensure NSDMI is + not present. */ + if (declspecs->storage_class == sc_static) + DECL_INITIAL (decl) = error_mark_node; + } } bad_specifiers (decl, BSP_FIELD, virtualp, --- gcc/cp/parser.c.jj 2011-12-14 08:10:59.000000000 +0100 +++ gcc/cp/parser.c 2011-12-14 17:30:51.150990128 +0100 @@ -21848,6 +21848,9 @@ cp_parser_late_parse_one_default_arg (cp tree parsed_arg; bool dummy; + if (default_arg == error_mark_node) + return error_mark_node; + /* Push the saved tokens for the default argument onto the parser's lexer stack. */ tokens = DEFARG_TOKENS (default_arg); --- gcc/testsuite/g++.dg/cpp0x/pr51463.C.jj 2011-12-14 17:33:37.034019780 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr51463.C 2011-12-14 17:33:46.081967283 +0100 @@ -0,0 +1,8 @@ +// PR c++/51463 +// { dg-do compile } +// { dg-options "-std=c++11" } + +struct A +{ + static virtual int i = 0; // { dg-error "both virtual and static|declared as" } +};