From patchwork Fri Dec 16 22:34:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 131929 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 D79C21007D7 for ; Sat, 17 Dec 2011 09:34:57 +1100 (EST) Received: (qmail 5370 invoked by alias); 16 Dec 2011 22:34:55 -0000 Received: (qmail 4710 invoked by uid 22791); 16 Dec 2011 22:34:54 -0000 X-SWARE-Spam-Status: No, hits=-5.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CX 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; Fri, 16 Dec 2011 22:34:40 +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 pBGMYeiV016885 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 16 Dec 2011 17:34:40 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pBGMYeG0026756 for ; Fri, 16 Dec 2011 17:34:40 -0500 Received: from [0.0.0.0] (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id pBGMYcuV031780 for ; Fri, 16 Dec 2011 17:34:39 -0500 Message-ID: <4EEBC77E.5020609@redhat.com> Date: Fri, 16 Dec 2011 17:34:38 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111112 Thunderbird/8.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/51461 (ice-on-invalid with static const data member) 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 literal_type_p doesn't like to see incomplete types, so let's check for that case first. Tested x86_64-pc-linux-gnu, applying to trunk. commit 0418652f7ecc0286565abc805d4728872eac32b9 Author: Jason Merrill Date: Fri Dec 16 14:04:01 2011 -0500 PR c++/51461 * decl.c (check_static_variable_definition): Check COMPLETE_TYPE_P before literal_type_p. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 919e235..fedc52c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5449,7 +5449,7 @@ check_initializer (tree decl, tree init, int flags, VEC(tree,gc) **cleanups) } else if (!COMPLETE_TYPE_P (type)) { - error ("%qD has incomplete type", decl); + error ("%q#D has incomplete type", decl); TREE_TYPE (decl) = error_mark_node; return NULL_TREE; } @@ -7807,7 +7807,10 @@ check_static_variable_definition (tree decl, tree type) return 0; else if (cxx_dialect >= cxx0x && !INTEGRAL_OR_ENUMERATION_TYPE_P (type)) { - if (literal_type_p (type)) + if (!COMPLETE_TYPE_P (type)) + error ("in-class initialization of static data member %q#D of " + "incomplete type", decl); + else if (literal_type_p (type)) permerror (input_location, "% needed for in-class initialization of " "static data member %q#D of non-integral type", decl); diff --git a/gcc/testsuite/g++.dg/init/static4.C b/gcc/testsuite/g++.dg/init/static4.C new file mode 100644 index 0000000..0cdc48b --- /dev/null +++ b/gcc/testsuite/g++.dg/init/static4.C @@ -0,0 +1,6 @@ +// PR c++/51461 + +struct A +{ + static const A a = 0; // { dg-error "incomplete|non-integral" } +};