From patchwork Fri Oct 14 18:44:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 119903 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 C2EC7B6F9A for ; Sat, 15 Oct 2011 05:46:30 +1100 (EST) Received: (qmail 22732 invoked by alias); 14 Oct 2011 18:46:27 -0000 Received: (qmail 22721 invoked by uid 22791); 14 Oct 2011 18:46:25 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD 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, 14 Oct 2011 18:46:12 +0000 Received: from ucsinet23.oracle.com (ucsinet23.oracle.com [156.151.31.71]) by rcsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p9EIk9fu024370 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 14 Oct 2011 18:46:11 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by ucsinet23.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p9EIk9D6007561 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 14 Oct 2011 18:46:09 GMT Received: from abhmt118.oracle.com (abhmt118.oracle.com [141.146.116.70]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p9EIk3tr003157; Fri, 14 Oct 2011 13:46:03 -0500 Received: from [192.168.1.4] (/79.43.235.225) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 14 Oct 2011 11:46:03 -0700 Message-ID: <4E9882FF.1050407@oracle.com> Date: Fri, 14 Oct 2011 20:44:15 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: Paolo Carlini CC: "gcc-patches@gcc.gnu.org" , Jason Merrill Subject: Re: [C++ Patch] PR 50732 References: <4E987E24.6000707@oracle.com> <4E987FDD.4060803@oracle.com> In-Reply-To: <4E987FDD.4060803@oracle.com> 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 On 10/14/2011 08:30 PM, Paolo Carlini wrote: > On 10/14/2011 08:23 PM, Paolo Carlini wrote: >> Hi, >> >> submitter complains that, at variance with C++11, __is_base_of >> doesn't handle an incomplete base type (the first parameter). The >> reason seems simple: in finish_trait_expr we try to complete *both* >> types instead of doing it where/when necessary. > Hmm, maybe we should be even more careful and call complete (type2) > only when > > NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) && > !same_type_ignoring_top_level_qualifiers_p (type1, type2) > > is true? Like this? Paolo. /////////////////// Index: testsuite/g++.dg/ext/is_base_of_incomplete.C =================================================================== --- testsuite/g++.dg/ext/is_base_of_incomplete.C (revision 0) +++ testsuite/g++.dg/ext/is_base_of_incomplete.C (revision 0) @@ -0,0 +1,7 @@ +template +struct non_instantiable +{ + typedef typename T::THIS_TYPE_CANNOT_BE_INSTANTIATED type; +}; + +int check[__is_base_of(non_instantiable, void) ? -1 : 1]; Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 179997) +++ cp/semantics.c (working copy) @@ -5276,10 +5276,6 @@ finish_trait_expr (cp_trait_kind kind, tree type1, return trait_expr; } - complete_type (type1); - if (type2) - complete_type (type2); - switch (kind) { case CPTK_HAS_NOTHROW_ASSIGN: @@ -5297,6 +5293,7 @@ finish_trait_expr (cp_trait_kind kind, tree type1, case CPTK_IS_POLYMORPHIC: case CPTK_IS_STD_LAYOUT: case CPTK_IS_TRIVIAL: + complete_type (type1); if (!check_trait_type (type1)) { error ("incomplete type %qT not allowed", type1); @@ -5306,11 +5303,14 @@ finish_trait_expr (cp_trait_kind kind, tree type1, case CPTK_IS_BASE_OF: if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2) - && !same_type_ignoring_top_level_qualifiers_p (type1, type2) - && !COMPLETE_TYPE_P (type2)) + && !same_type_ignoring_top_level_qualifiers_p (type1, type2)) { - error ("incomplete type %qT not allowed", type2); - return error_mark_node; + complete_type (type2); + if (!COMPLETE_TYPE_P (type2)) + { + error ("incomplete type %qT not allowed", type2); + return error_mark_node; + } } break;