From patchwork Mon Mar 25 18:26:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1064682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-498400-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jC8QN+KL"; dkim-atps=neutral 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 44SjQS5Xf7z9sNt for ; Tue, 26 Mar 2019 05:26:38 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version :content-transfer-encoding; q=dns; s=default; b=rX2iVoluWAk0oNu6 HqIkMB3qp2pW6qSaZVR9MEykVETsG4U2FKcxoXfxld/uD3VX/y2B7yxsamv0P+V4 T/IKb1CryCcXdmfhPxMxNxXw59lmgmkKCP4iIoLKTg/TTtaUiMPJ/dTPA6pZ2x/J oy45ENqh3cNJgvBasfbdlvy/TWw= 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:from :to:subject:date:message-id:mime-version :content-transfer-encoding; s=default; bh=vSqjTu4DknRPJNaRUpuRRu jctj0=; b=jC8QN+KLWmKzRS+InoAB9SqUTkrLwI2Y8lcdh/R3S3jjXK1Jrl0bdC 8jefP7uoQmb13Kld5JeIR8tXz/lKrmATVu89v1EzCYrP1hvH3loUjX4YtaGY7/Rc puvbl7qgy3wqQUK+kI/xoxAxiZGqnbhuXkqQOiJWLdSAKr2XL5xtc= Received: (qmail 68721 invoked by alias); 25 Mar 2019 18:26:29 -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 68707 invoked by uid 89); 25 Mar 2019 18:26:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=Simplified, visitor X-HELO: mail-qt1-f193.google.com Received: from mail-qt1-f193.google.com (HELO mail-qt1-f193.google.com) (209.85.160.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 25 Mar 2019 18:26:27 +0000 Received: by mail-qt1-f193.google.com with SMTP id w5so11446592qtb.11 for ; Mon, 25 Mar 2019 11:26:27 -0700 (PDT) Received: from orpheus.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id p46sm13074253qtc.41.2019.03.25.11.26.24 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Mar 2019 11:26:24 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] PR c++/87748 - substitution failure error with decltype. Date: Mon, 25 Mar 2019 14:26:23 -0400 Message-Id: <20190325182623.31637-1-jason@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes This issue is similar to PR 87480; in both cases we were doing non-dependent substitution with processing_template_decl set, leading to member access expressions seeming still instantiation-dependent, and therefore decltype not being simplified to its actual type. And as in that PR, the fix is to clear processing_template_decl while substituting a default template argument. Tested x86_64-pc-linux-gnu, applying to trunk. * pt.c (most_specialized_partial_spec): Clear processing_template_decl. --- gcc/cp/pt.c | 5 ++ gcc/testsuite/g++.dg/cpp0x/sfinae64.C | 69 +++++++++++++++++++++++++++ gcc/cp/ChangeLog | 6 +++ 3 files changed, 80 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/sfinae64.C base-commit: 1954998fae2cf349308b55faca0c7b0ecf1b2462 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index afb7ece57d1..05d5371d8a6 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -23550,6 +23550,11 @@ most_specialized_partial_spec (tree target, tsubst_flags_t complain) args = INNERMOST_TEMPLATE_ARGS (args); } + /* The caller hasn't called push_to_top_level yet, but we need + get_partial_spec_bindings to be done in non-template context so that we'll + fully resolve everything. */ + processing_template_decl_sentinel ptds; + for (t = DECL_TEMPLATE_SPECIALIZATIONS (main_tmpl); t; t = TREE_CHAIN (t)) { tree spec_args; diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae64.C b/gcc/testsuite/g++.dg/cpp0x/sfinae64.C new file mode 100644 index 00000000000..f35b81268a2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/sfinae64.C @@ -0,0 +1,69 @@ +// PR c++/87748 +// { dg-do compile { target c++11 } } + +template T&& declval(); +template struct enable_if; +template struct enable_if { typedef T type; }; +struct true_type { static const bool value = true; }; +struct false_type { static const bool value = false; }; + +struct string +{ + string (const char *p); +}; + +/// Template to map all type arguments to void, useful for SFINAE, see also WG21 N3911. +template using void_t = void; + +/// REQUIRES - Simplified version of enable_if<> to use SFINAE in function templates. +template using REQUIRES = typename ::enable_if::type; + +/// DerivesString - Check if @a T is of type 'string'. +template struct DerivesString +{ + static const int value = __is_same_as (T, string); +}; + +/// Has__aida_visit__ - Check if @a T provides a member template __aida_visit__<>(Visitor). +template struct Has__aida_visit__ : false_type {}; +template +struct Has__aida_visit__().template __aida_visit__ (*(V*) 0)) >> : true_type {}; + +struct Foo { + template void __accept__ (V*); +}; + +/// Base template for Visitor classes, dispatches operator() to visit_() methods. +template +class VisitorDispatcher { + DerivedVisitor* derived () { return static_cast (this); } +protected: + typedef const char* Name; ///< Member name argument type for visit() methods. +public: + + // dispatch for calls like: visitor (field, "field"); + + template::value) > = true> + void operator() (A &a, Name n) + { return derived()->visit_string (a, n); } +}; + +class PspecVisitor : public VisitorDispatcher { +public: + void visit_string (::string &a, Name name); +}; + +int +main (int argc, char *argv[]) +{ +#ifdef WITHASSERT // define this to fix g++-8.1.1 + static_assert (Has__aida_visit__::value == false, ""); +#endif + PspecVisitor v; + string str ("A string"); + v (str, "some_string"); + static_assert (Has__aida_visit__::value == false, ""); + return 0; +} +// g++ -std=gnu++14 -Wall -O2 aidavisit.cc && ./a.out diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 16f1b8e1aae..66171b2ccdf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-03-25 Jason Merrill + + PR c++/87748 - substitution failure error with decltype. + * pt.c (most_specialized_partial_spec): Clear + processing_template_decl. + 2019-03-22 Jakub Jelinek PR c++/60702