From patchwork Wed May 7 17:15:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 346746 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 7EB45140117 for ; Thu, 8 May 2014 03:17:52 +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:content-type; q=dns; s=default; b=VmjtbdDU/cLJMF1MHcneT2uBQ7ToBXJuOV2Bi3mQPy6 g/MoEwJWB4ObMmObxXEyBy43McleaHzSA+GHQLv9eDJ5NSD0oXPclqLXRTYtePm+ XYhtxxBw+xoUd9LGsAqRLMgJTPXfu+oum90C07y3adJNPJiPp5w9aJ+TC/VLrlCI = 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:content-type; s=default; bh=ifvPTBmpwhJt93tlv2vf0ogmr38=; b=qRhPUu218zjY6vYNL rgIJESK2WaT47PEtLUWQt4oH6w07sbpHfBqhDkfgIopzM1HSlqDXicV3s95NzUkV UZ4h3SDNXnPfiXH0VWxQpBpaK4wR391dLTXxpADJfjMmJsoXKav61A34hOCjRgAn xf8A3rxqTF9hBasqHqkfV437ps= Received: (qmail 2076 invoked by alias); 7 May 2014 17:17: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 2059 invoked by uid 89); 7 May 2014 17:17: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: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 07 May 2014 17:17:40 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s47HHbdn027812 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 7 May 2014 17:17:37 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s47HHar8011099 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 7 May 2014 17:17:36 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s47HHaG9006817; Wed, 7 May 2014 17:17:36 GMT Received: from [192.168.1.4] (/79.35.208.86) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 07 May 2014 10:17:35 -0700 Message-ID: <536A6A3A.7050202@oracle.com> Date: Wed, 07 May 2014 19:15:38 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 61083 X-IsSubscribed: yes Hi, curiously, convert_nontype_argument still has most of its error calls not protected by complain & tf_error. The obvious fix works for this SFINAE issue. Not a regression, but could be safe for the branch too? Tested x86_64-linux. Thanks, Paolo. ////////////////////// /cp 2014-05-07 Paolo Carlini PR c++/61083 * pt.c (convert_nontype_argument): Protect all the error calls with complain & tf_error. /testsuite 2014-05-07 Paolo Carlini PR c++/61083 * g++.dg/cpp0x/sfinae50.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 210180) +++ cp/pt.c (working copy) @@ -5812,17 +5812,18 @@ convert_nontype_argument (tree type, tree expr, ts { if (VAR_P (expr)) { - error ("%qD is not a valid template argument " - "because %qD is a variable, not the address of " - "a variable", - expr, expr); + if (complain & tf_error) + error ("%qD is not a valid template argument " + "because %qD is a variable, not the address of " + "a variable", expr, expr); return NULL_TREE; } if (POINTER_TYPE_P (expr_type)) { - error ("%qE is not a valid template argument for %qT " - "because it is not the address of a variable", - expr, type); + if (complain & tf_error) + error ("%qE is not a valid template argument for %qT " + "because it is not the address of a variable", + expr, type); return NULL_TREE; } /* Other values, like integer constants, might be valid @@ -5837,23 +5838,24 @@ convert_nontype_argument (tree type, tree expr, ts ? TREE_OPERAND (expr, 0) : expr); if (!VAR_P (decl)) { - error ("%qE is not a valid template argument of type %qT " - "because %qE is not a variable", - expr, type, decl); + if (complain & tf_error) + error ("%qE is not a valid template argument of type %qT " + "because %qE is not a variable", expr, type, decl); return NULL_TREE; } else if (cxx_dialect < cxx11 && !DECL_EXTERNAL_LINKAGE_P (decl)) { - error ("%qE is not a valid template argument of type %qT " - "because %qD does not have external linkage", - expr, type, decl); + if (complain & tf_error) + error ("%qE is not a valid template argument of type %qT " + "because %qD does not have external linkage", + expr, type, decl); return NULL_TREE; } else if (cxx_dialect >= cxx11 && decl_linkage (decl) == lk_none) { - error ("%qE is not a valid template argument of type %qT " - "because %qD has no linkage", - expr, type, decl); + if (complain & tf_error) + error ("%qE is not a valid template argument of type %qT " + "because %qD has no linkage", expr, type, decl); return NULL_TREE; } } @@ -5881,15 +5883,17 @@ convert_nontype_argument (tree type, tree expr, ts if (!at_least_as_qualified_p (TREE_TYPE (type), expr_type)) { - error ("%qE is not a valid template argument for type %qT " - "because of conflicts in cv-qualification", expr, type); + if (complain & tf_error) + error ("%qE is not a valid template argument for type %qT " + "because of conflicts in cv-qualification", expr, type); return NULL_TREE; } if (!real_lvalue_p (expr)) { - error ("%qE is not a valid template argument for type %qT " - "because it is not an lvalue", expr, type); + if (complain & tf_error) + error ("%qE is not a valid template argument for type %qT " + "because it is not an lvalue", expr, type); return NULL_TREE; } @@ -5905,9 +5909,10 @@ convert_nontype_argument (tree type, tree expr, ts expr = TREE_OPERAND (expr, 0); if (DECL_P (expr)) { - error ("%q#D is not a valid template argument for type %qT " - "because a reference variable does not have a constant " - "address", expr, type); + if (complain & tf_error) + error ("%q#D is not a valid template argument for type %qT " + "because a reference variable does not have a constant " + "address", expr, type); return NULL_TREE; } } @@ -5914,17 +5919,19 @@ convert_nontype_argument (tree type, tree expr, ts if (!DECL_P (expr)) { - error ("%qE is not a valid template argument for type %qT " - "because it is not an object with external linkage", - expr, type); + if (complain & tf_error) + error ("%qE is not a valid template argument for type %qT " + "because it is not an object with external linkage", + expr, type); return NULL_TREE; } if (!DECL_EXTERNAL_LINKAGE_P (expr)) { - error ("%qE is not a valid template argument for type %qT " - "because object %qD has not external linkage", - expr, type, expr); + if (complain & tf_error) + error ("%qE is not a valid template argument for type %qT " + "because object %qD has not external linkage", + expr, type, expr); return NULL_TREE; } @@ -5966,9 +5973,13 @@ convert_nontype_argument (tree type, tree expr, ts { if (TREE_CODE (expr) == ADDR_EXPR) { - error ("%qE is not a valid template argument for type %qT " - "because it is a pointer", expr, type); - inform (input_location, "try using %qE instead", TREE_OPERAND (expr, 0)); + if (complain & tf_error) + { + error ("%qE is not a valid template argument for type %qT " + "because it is a pointer", expr, type); + inform (input_location, "try using %qE instead", + TREE_OPERAND (expr, 0)); + } return NULL_TREE; } @@ -6006,13 +6017,16 @@ convert_nontype_argument (tree type, tree expr, ts provide a superior diagnostic. */ if (!same_type_p (TREE_TYPE (expr), type)) { - error ("%qE is not a valid template argument for type %qT " - "because it is of type %qT", expr, type, - TREE_TYPE (expr)); - /* If we are just one standard conversion off, explain. */ - if (can_convert_standard (type, TREE_TYPE (expr), complain)) - inform (input_location, - "standard conversions are not allowed in this context"); + if (complain & tf_error) + { + error ("%qE is not a valid template argument for type %qT " + "because it is of type %qT", expr, type, + TREE_TYPE (expr)); + /* If we are just one standard conversion off, explain. */ + if (can_convert_standard (type, TREE_TYPE (expr), complain)) + inform (input_location, + "standard conversions are not allowed in this context"); + } return NULL_TREE; } } @@ -6035,8 +6049,9 @@ convert_nontype_argument (tree type, tree expr, ts { if (expr != nullptr_node) { - error ("%qE is not a valid template argument for type %qT " - "because it is of type %qT", expr, type, TREE_TYPE (expr)); + if (complain & tf_error) + error ("%qE is not a valid template argument for type %qT " + "because it is of type %qT", expr, type, TREE_TYPE (expr)); return NULL_TREE; } return expr; Index: testsuite/g++.dg/cpp0x/sfinae50.C =================================================================== --- testsuite/g++.dg/cpp0x/sfinae50.C (revision 0) +++ testsuite/g++.dg/cpp0x/sfinae50.C (working copy) @@ -0,0 +1,41 @@ +// PR c++/61083 +// { dg-do compile { target c++11 } } + +template T declval(); + +template +struct is_same { + static const bool value = false; +}; + +template +struct is_same { + static const bool value = true; +}; + +struct true_type {}; +struct false_type {}; + +template +struct is_foo { +private: + template struct helper {}; + + template static auto + test(Z z) -> decltype(helper(), true_type()); + + template static auto test(...) -> false_type; + +public: + enum { value = is_same(declval())), true_type>::value }; +}; + +struct A { + int foo(); + void foo() const; +}; + +struct A1 : public A {}; + +static_assert (is_foo::value == 1, ""); +static_assert (is_foo::value == 0, "");