From patchwork Tue May 20 00:09:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 350446 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C9D71140083 for ; Tue, 20 May 2014 10:11:51 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=nVpiMb8OIzwOXu80p FCcdRG7JAl7yMB8fKb1vCklBp7ciwX/LOXBNvVcwfLFhzp2D+8FjsUfQFri8nKFs 6QmW5M4YMXdzOnIVunISIpsuSpnd9/8C7Fm6SpqZ5x7qGd608nXIFt8wiolXemub EbmS5nM9RPvHPp93NdAi97PHVQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=wpqXfxu3uHvZmBRoAvt16bJ c+fU=; b=d2rsuypovTRfdmABUyEGplNydQ7EIofYEO+ByLEyaZ3CRD8NiE+abVR 9T4ipe6lT0jMo0IekGM45Zap4lmiRcPPCt0IgMuLHcv28cQCbSTW8aJuRpYFYuA8 R/CKf17H352RdCklaqq0IXoarIqvtUwqTZZFzeCDGhNZ5nlyli9Y= Received: (qmail 21759 invoked by alias); 20 May 2014 00:11:43 -0000 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 Received: (qmail 21747 invoked by uid 89); 20 May 2014 00:11:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 20 May 2014 00:11:41 +0000 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s4K0BctC014894 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 20 May 2014 00:11:39 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id s4K0BZLV006126 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 20 May 2014 00:11:38 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s4K0BZfU020774; Tue, 20 May 2014 00:11:35 GMT Received: from [192.168.1.4] (/79.36.17.99) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 19 May 2014 17:11:34 -0700 Message-ID: <537A9D2B.7030507@oracle.com> Date: Tue, 20 May 2014 02:09:15 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: Re: [C++ Patch] PR 58664 References: <537A8913.7000509@oracle.com> In-Reply-To: <537A8913.7000509@oracle.com> X-IsSubscribed: yes ... in fact, I need to be more careful when comparing the types, also because of cv-qualifiers, eg, for: struct S { const S s[1] = { 0 }; }; the trees for S and const S are definitely different. Done in the attached. Thanks, Paolo. /////////////////////// /cp 2014-05-20 Paolo Carlini PR c++/58664 * decl.c (grokdeclarator): Check the element type of an incomplete array type; call cxx_incomplete_type_error. * typeck2.c (cxx_incomplete_type_inform): New. (cxx_incomplete_type_diagnostic): Use it. /testsuite 2014-05-20 Paolo Carlini PR c++/58664 * g++.dg/cpp0x/nsdmi-union6.C: New. * g++.dg/parse/pr58664.C: Likewise. * g++.dg/parse/crash31.C: Tweak. * g++.dg/parse/struct-4.C: Likewise. * g++.dg/template/error2.C: Likewise. * g++.dg/template/inherit8.C: Likewise. * g++.dg/template/offsetof2.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 210622) +++ cp/decl.c (working copy) @@ -10586,11 +10586,12 @@ grokdeclarator (const cp_declarator *declarator, } else if (!staticp && !dependent_type_p (type) && !COMPLETE_TYPE_P (complete_type (type)) - && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) + && (TREE_CODE (type) != ARRAY_TYPE + || !COMPLETE_TYPE_P (TREE_TYPE (type)) + || initialized == 0)) { if (unqualified_id) - error ("field %qD has incomplete type %qT", - unqualified_id, type); + cxx_incomplete_type_error (unqualified_id, type); else error ("name %qT has incomplete type", type); Index: cp/typeck2.c =================================================================== --- cp/typeck2.c (revision 210623) +++ cp/typeck2.c (working copy) @@ -429,6 +429,25 @@ abstract_virtuals_error (abstract_class_use use, t return abstract_virtuals_error_sfinae (use, type, tf_warning_or_error); } +/* Print an inform about the declaration of the incomplete type TYPE. */ + +static void +cxx_incomplete_type_inform (const_tree type) +{ + location_t loc = DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)); + tree ptype = strip_top_quals (CONST_CAST_TREE (type)); + + if (current_class_type + && TYPE_BEING_DEFINED (current_class_type) + && same_type_p (ptype, current_class_type)) + inform (loc, "definition of %q#T is not complete until " + "the closing brace", ptype); + else if (!TYPE_TEMPLATE_INFO (ptype)) + inform (loc, "forward declaration of %q#T", ptype); + else + inform (loc, "declaration of %q#T", ptype); +} + /* Print an error message for invalid use of an incomplete type. VALUE is the expression that was used (or 0 if that isn't known) and TYPE is the type that was invalid. DIAG_KIND indicates the @@ -469,14 +488,7 @@ cxx_incomplete_type_diagnostic (const_tree value, "invalid use of incomplete type %q#T", type); if (complained) - { - if (!TYPE_TEMPLATE_INFO (type)) - inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)), - "forward declaration of %q#T", type); - else - inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)), - "declaration of %q#T", type); - } + cxx_incomplete_type_inform (type); break; case VOID_TYPE: Index: testsuite/g++.dg/cpp0x/nsdmi-union6.C =================================================================== --- testsuite/g++.dg/cpp0x/nsdmi-union6.C (revision 0) +++ testsuite/g++.dg/cpp0x/nsdmi-union6.C (working copy) @@ -0,0 +1,56 @@ +// PR c++/58664 +// { dg-do compile { target c++11 } } + +struct F; // { dg-message "forward declaration" } + +union U // { dg-message "not complete" } +{ + U u[1] = { 0 }; // { dg-error "incomplete type" } +}; + +template +union UT // { dg-message "not complete" } +{ + UT u[1] = { 0 }; // { dg-error "incomplete type" } +}; + +template union UT; + +union UF +{ + F u[1] = { 0 }; // { dg-error "incomplete type" } +}; + +template +union UFT +{ + F u[1] = { 0 }; // { dg-error "incomplete type" } +}; + +template union UFT; + +struct S // { dg-message "not complete" } +{ + S s[1] = { 0 }; // { dg-error "incomplete type" } +}; + +template +struct ST // { dg-message "not complete" } +{ + ST s[1] = { 0 }; // { dg-error "incomplete type" } +}; + +template class ST; + +struct SF +{ + F s[1] = { 0 }; // { dg-error "incomplete type" } +}; + +template +struct SFT +{ + F s[1] = { 0 }; // { dg-error "incomplete type" } +}; + +template class SFT; Index: testsuite/g++.dg/parse/crash31.C =================================================================== --- testsuite/g++.dg/parse/crash31.C (revision 210624) +++ testsuite/g++.dg/parse/crash31.C (working copy) @@ -1,4 +1,4 @@ -struct A // { dg-message "forward declaration" } +struct A // { dg-message "not complete" } { A : A; // { dg-error "expected|incomplete" } A : B; // { dg-error "not declared|incomplete" } Index: testsuite/g++.dg/parse/pr58664.C =================================================================== --- testsuite/g++.dg/parse/pr58664.C (revision 0) +++ testsuite/g++.dg/parse/pr58664.C (working copy) @@ -0,0 +1,66 @@ +// PR c++/58664 +// { dg-do compile { target c++11 } } + +struct F; // { dg-message "forward declaration" } + +union U // { dg-message "not complete" } +{ + U u; // { dg-error "incomplete type" } +}; + +union CU // { dg-message "not complete" } +{ + const CU u; // { dg-error "incomplete type" } +}; + +template +union UT // { dg-message "not complete" } +{ + UT u; // { dg-error "incomplete type" } +}; + +template union UT; + +union UF +{ + F u; // { dg-error "incomplete type" } +}; + +template +union UFT +{ + F u; // { dg-error "incomplete type" } +}; + +template union UFT; + +struct S // { dg-message "not complete" } +{ + S s; // { dg-error "incomplete type" } +}; + +struct VS // { dg-message "not complete" } +{ + volatile VS s; // { dg-error "incomplete type" } +}; + +template +struct ST // { dg-message "not complete" } +{ + ST s; // { dg-error "incomplete type" } +}; + +template class ST; + +struct SF +{ + F s; // { dg-error "incomplete type" } +}; + +template +struct SFT +{ + F s; // { dg-error "incomplete type" } +}; + +template class SFT; Index: testsuite/g++.dg/parse/struct-4.C =================================================================== --- testsuite/g++.dg/parse/struct-4.C (revision 210624) +++ testsuite/g++.dg/parse/struct-4.C (working copy) @@ -4,7 +4,7 @@ struct A { int i; - struct A a; /* { dg-error "has incomplete type" } */ + struct A a; /* { dg-error "incomplete type" } */ }; void foo() Index: testsuite/g++.dg/template/error2.C =================================================================== --- testsuite/g++.dg/template/error2.C (revision 210624) +++ testsuite/g++.dg/template/error2.C (working copy) @@ -7,8 +7,7 @@ template struct X { - T m; // { dg-error "void" "void" } - // { dg-error "incomplete type" "incomplete" { target *-*-* } 10 } + T m; // { dg-error "incomplete type|invalid use" } }; template Index: testsuite/g++.dg/template/inherit8.C =================================================================== --- testsuite/g++.dg/template/inherit8.C (revision 210624) +++ testsuite/g++.dg/template/inherit8.C (working copy) @@ -4,7 +4,7 @@ template struct A { template - struct B : public A > // { dg-message "declaration" } + struct B : public A > // { dg-message "not complete" } { struct C : public B // { dg-error "incomplete" } { Index: testsuite/g++.dg/template/offsetof2.C =================================================================== --- testsuite/g++.dg/template/offsetof2.C (revision 210624) +++ testsuite/g++.dg/template/offsetof2.C (working copy) @@ -1,7 +1,7 @@ // PR c++/49085 template -struct A // { dg-message "declaration" } +struct A // { dg-message "not complete" } { int i, j; int ar[__builtin_offsetof(A,j)]; // { dg-error "incomplete type" }