From patchwork Wed May 6 21:48:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1284810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=QKDjohA7; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49HVbG5Vm6z9sSm for ; Thu, 7 May 2020 07:48:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8AEC0394844B; Wed, 6 May 2020 21:48:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8AEC0394844B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588801717; bh=4q4wjlGH46qGdu+vKYUwJRp6b3NXRDpLZOxsFJHLh9s=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QKDjohA7+YuzKYwbdP0F6OoDdrncGpzV/bdsFVe+vVZSzh0XT/MBuK4vOHALg72PQ 2TkibtfOPRwlcdqxZa757oGrHQ39EmPut99S9WygD+41PJf2fuJPT26aJsM7WAcagy JhtFjUhxJjZrIiXES5ujtgCroePL0XnZuU8rSLOM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 79482386F819 for ; Wed, 6 May 2020 21:48:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 79482386F819 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-323-RwT5FzPsOWG64HS7BxTrYQ-1; Wed, 06 May 2020 17:48:32 -0400 X-MC-Unique: RwT5FzPsOWG64HS7BxTrYQ-1 Received: by mail-qt1-f197.google.com with SMTP id f56so4142893qte.18 for ; Wed, 06 May 2020 14:48:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xBGCkB2NVJKg8JIV3/pcI9LSqFZXOH5TOCQVzWVh82Y=; b=IuJh4pTZRq73hXyTcji5jbOcgLGakkALZfw3ng6rBK4eldLKkSjA5PLqZIFLXfi5eK ux+Ev9BBILLX61IVaYuEF2rW3EmKJY8ncknQCAcx3Y1elsV35MfsA3rYERoDpx4TFbg0 7bDzHkM9gnUrZYzMA125yNMfrpWg1qse6aQrX07UHxLFg8pJX2vNClySMiA9mHakksgm LH9XeILv276cuZx8YqkyQAkxbv6Atg4Z2x7QV+SDuzbK71QU4S+nerg3z9/BD2KFm+Rz wMFfwJithHXEXqMsu1ICNqpFWwPRLdlUyL3L9oPTbKyw8wFZqHNTYXKlVwaeQO5n2qf3 sN7g== X-Gm-Message-State: AGi0PubIZ9xks2VLTEigp8YnM8AQf2fkcpgQB5djtXjLoXj7YENS1dUq sFYdHk3CuyutnJbqjBbQbckk/IvLqRV07MBX4BLEMbEtEPbWtVo7bN9BwF+z1D+q7eNXNlF9jA3 RYyW7wmimNboVrY6s6w== X-Received: by 2002:ac8:3421:: with SMTP id u30mr11304528qtb.303.1588801711607; Wed, 06 May 2020 14:48:31 -0700 (PDT) X-Google-Smtp-Source: APiQypIaVd6a5BkplCQAi0QTAajb6WEbZ7f47018rEzAQ2APPVB+vXqcgnw8PK813vxHWM5lRIhhLg== X-Received: by 2002:ac8:3421:: with SMTP id u30mr11304501qtb.303.1588801711235; Wed, 06 May 2020 14:48:31 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id i42sm2851239qtc.83.2020.05.06.14.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 14:48:30 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Missing SFINAE with lookup_fnfields [PR78446] Date: Wed, 6 May 2020 17:48:28 -0400 Message-Id: <20200506214828.1820908-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.2.561.g07d8ea56f2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-20.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Here we're failing to do SFINAE in build_op_call when looking up the class's operator() via lookup_fnfields, which calls lookup_member always with complain=tf_warning_or_error. And from there we complain about an ambiguous lookup for operator(). This patch fixes this by adding a tsubst_flags_t parameter to lookup_fnfields and adjusting all its callers appropriately. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK to commit? gcc/cp/ChangeLog: PR c++/78446 * call.c (build_op_call): Pass complain to lookup_fnfields. (build_special_member_call): Likewise. * class.c (type_requires_array_cookie): Pass tf_warning_or_error to lookup_fnfields. * cp-tree.h (lookup_fnfields): Add tsubst_flags_t parameter. * except.c (build_throw): Pass tf_warning_or_error to lookup_fnfields. * init.c (build_new_1): Pass complain to lookup_fnfields. * method.c (locate_fn_flags): Likewise. * name-lookup.c (lookup_name_real_1): Pass tf_warning_or_error to lookup_fnfields. * pt.c (tsubst_baselink): Pass complain to lookup_fnfields. * search.c (lookup_fnfields): New 'complain' parameter. Pass it to lookup_member. gcc/testsuite/ChangeLog: PR c++/78446 * g++.dg/template/sfinae30.C: New test. --- gcc/cp/call.c | 8 ++++---- gcc/cp/class.c | 2 +- gcc/cp/cp-tree.h | 2 +- gcc/cp/except.c | 3 ++- gcc/cp/init.c | 2 +- gcc/cp/method.c | 2 +- gcc/cp/name-lookup.c | 3 ++- gcc/cp/pt.c | 3 ++- gcc/cp/search.c | 5 +++-- gcc/testsuite/g++.dg/template/sfinae30.C | 14 ++++++++++++++ 10 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/sfinae30.C diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 1182d3ae642..a7c7f471b60 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4779,7 +4779,7 @@ build_op_call_1 (tree obj, vec **args, tsubst_flags_t complain) if (TYPE_BINFO (type)) { - fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1); + fns = lookup_fnfields (TYPE_BINFO (type), call_op_identifier, 1, complain); if (fns == error_mark_node) return error_mark_node; } @@ -5965,7 +5965,7 @@ add_operator_candidates (z_candidate **candidates, tree arg2_type = nargs > 1 ? TREE_TYPE ((*arglist)[1]) : NULL_TREE; if (CLASS_TYPE_P (arg1_type)) { - tree fns = lookup_fnfields (arg1_type, fnname, 1); + tree fns = lookup_fnfields (arg1_type, fnname, 1, complain); if (fns == error_mark_node) return error_mark_node; if (fns) @@ -6772,7 +6772,7 @@ build_op_delete_call (enum tree_code code, tree addr, tree size, Therefore, we ask lookup_fnfields to complain about ambiguity. */ { - fns = lookup_fnfields (TYPE_BINFO (type), fnname, 1); + fns = lookup_fnfields (TYPE_BINFO (type), fnname, 1, complain); if (fns == error_mark_node) return error_mark_node; } @@ -9793,7 +9793,7 @@ build_special_member_call (tree instance, tree name, vec **args, } } - fns = lookup_fnfields (binfo, name, 1); + fns = lookup_fnfields (binfo, name, 1, complain); /* When making a call to a constructor or destructor for a subobject that uses virtual base classes, pass down a pointer to a VTT for diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 1f524a31917..16bfa313ed2 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -5644,7 +5644,7 @@ type_requires_array_cookie (tree type) a cookie. */ fns = lookup_fnfields (TYPE_BINFO (type), ovl_op_identifier (false, VEC_DELETE_EXPR), - /*protect=*/0); + /*protect=*/0, tf_warning_or_error); /* If there are no `operator []' members, or the lookup is ambiguous, then we don't need a cookie. */ if (!fns || fns == error_mark_node) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 39c7ddb697a..a29102b1ab5 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7058,7 +7058,7 @@ extern tree dcast_base_hint (tree, tree); extern int accessible_p (tree, tree, bool); extern int accessible_in_template_p (tree, tree); extern tree lookup_field (tree, tree, int, bool); -extern tree lookup_fnfields (tree, tree, int); +extern tree lookup_fnfields (tree, tree, int, tsubst_flags_t); extern tree lookup_member (tree, tree, int, bool, tsubst_flags_t, access_failure_info *afi = NULL); diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 7e93c51f9ea..9e1aa5085d4 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -821,7 +821,8 @@ build_throw (location_t loc, tree exp) if (type_build_dtor_call (TREE_TYPE (object))) { tree dtor_fn = lookup_fnfields (TYPE_BINFO (TREE_TYPE (object)), - complete_dtor_identifier, 0); + complete_dtor_identifier, 0, + tf_warning_or_error); dtor_fn = BASELINK_FUNCTIONS (dtor_fn); mark_used (dtor_fn); if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (object))) diff --git a/gcc/cp/init.c b/gcc/cp/init.c index c7ae9404e04..3f572cdc473 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3276,7 +3276,7 @@ build_new_1 (vec **placement, tree type, tree nelts, /* Create the argument list. */ vec_safe_insert (*placement, 0, size); /* Do name-lookup to find the appropriate operator. */ - fns = lookup_fnfields (elt_type, fnname, /*protect=*/2); + fns = lookup_fnfields (elt_type, fnname, /*protect=*/2, complain); if (fns == NULL_TREE) { if (complain & tf_error) diff --git a/gcc/cp/method.c b/gcc/cp/method.c index fb2dd47013f..b64b6a8254e 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1646,7 +1646,7 @@ locate_fn_flags (tree type, tree name, tree argtype, int flags, } } - fns = lookup_fnfields (binfo, name, 0); + fns = lookup_fnfields (binfo, name, 0, complain); rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain); if (fn && rval == error_mark_node) diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 9b68b15be60..27e8ff62ea3 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -6455,7 +6455,8 @@ lookup_name_real_1 (tree name, int prefer_type, int nonclass, bool block_p, /* Lookup the conversion operator in the class. */ class_type = level->this_entity; - operators = lookup_fnfields (class_type, name, /*protect=*/0); + operators = lookup_fnfields (class_type, name, /*protect=*/0, + tf_warning_or_error); if (operators) return operators; } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2ed6d0e7457..92358d06915 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16031,7 +16031,8 @@ tsubst_baselink (tree baselink, tree object_type, /* Treat as-if non-dependent below. */ dependent_p = false; - baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1); + baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1, + complain); if (!baselink) { if ((complain & tf_error) diff --git a/gcc/cp/search.c b/gcc/cp/search.c index 6eada2d3788..c6eb95380d0 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -1347,10 +1347,11 @@ lookup_field (tree xbasetype, tree name, int protect, bool want_type) return NULL_TREE. */ tree -lookup_fnfields (tree xbasetype, tree name, int protect) +lookup_fnfields (tree xbasetype, tree name, int protect, + tsubst_flags_t complain) { tree rval = lookup_member (xbasetype, name, protect, /*want_type=*/false, - tf_warning_or_error); + complain); /* Ignore non-functions, but propagate the ambiguity list. */ if (!error_operand_p (rval) diff --git a/gcc/testsuite/g++.dg/template/sfinae30.C b/gcc/testsuite/g++.dg/template/sfinae30.C new file mode 100644 index 00000000000..b31a5aeb73a --- /dev/null +++ b/gcc/testsuite/g++.dg/template/sfinae30.C @@ -0,0 +1,14 @@ +// PR c++/78446 +// { dg-do compile { target c++11 } } + +struct A { void operator()(); }; +struct B { void operator()(); }; +struct C : A, B {}; + +template +decltype(T()()) foo(int); + +template int foo(...); + +using type = decltype(foo(0)); +using type = int;