From patchwork Fri Oct 14 18:23:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 119892 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 1B42FB700E for ; Sat, 15 Oct 2011 05:25:54 +1100 (EST) Received: (qmail 21048 invoked by alias); 14 Oct 2011 18:25:52 -0000 Received: (qmail 21033 invoked by uid 22791); 14 Oct 2011 18:25:51 -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 acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 14 Oct 2011 18:25:37 +0000 Received: from ucsinet23.oracle.com (ucsinet23.oracle.com [156.151.31.71]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p9EIPXEG009868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 14 Oct 2011 18:25:34 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet23.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p9EIPWBf011080 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 14 Oct 2011 18:25:32 GMT Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p9EIPNCJ028818; Fri, 14 Oct 2011 13:25:26 -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:25:23 -0700 Message-ID: <4E987E24.6000707@oracle.com> Date: Fri, 14 Oct 2011 20:23:32 +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: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 50732 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 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. Tested x86_64-linux. Ok? Thanks, Paolo. /////////////////// /cp 2011-10-14 Paolo Carlini PR c++/50732 * semantics.c (finish_trait_expr): Do not try to instantiate the the base type of an __is_base_of trait. /testsuite 2011-10-14 Paolo Carlini PR c++/50732 * g++.dg/ext/is_base_of_incomplete.C: New. 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); @@ -5305,6 +5302,7 @@ finish_trait_expr (cp_trait_kind kind, tree type1, break; case CPTK_IS_BASE_OF: + complete_type (type2); 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))