From patchwork Thu Apr 12 20:02:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 897792 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-476308-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="maIZF5Ub"; 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 40MX0J36Blz9s1l for ; Fri, 13 Apr 2018 06:03:26 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=jzLwlGj/UlmP647ErsDQ4A70QAH8769EJGxg/eDS49dvtT YjT90vw6yjOPxe0GvpV6AmskJNBqI03P0U2OiUwv22uTaqcAlqPVToAv5SjpVGz9 nwsMHMWFA2AfoxemGcda9kYZDiKvsMGpKqUwWCNiX2QJjbFm23DyTEbiD16xA= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=c+odh0Sv6lsdkh/Ltdnt0mxyoVI=; b=maIZF5Ub/ALK027DU6os X1s4TU5Ljb+G9uZctGdoNc13i9BSYHd60wfL+9SqKlt3f3fRGn/Ezwx4LtMsI+f9 erWBszs27GHjECGCPs4ymUnnAH+XKJuML2wGUAed5teifoOV3lTWKrwt7gq9Il1D anPk2irxbUB7XiWNumrE7Ec= Received: (qmail 20265 invoked by alias); 12 Apr 2018 20:03:18 -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 18778 invoked by uid 89); 12 Apr 2018 20:03:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 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.2 spammy=theyre, they're X-HELO: mail-ot0-f177.google.com Received: from mail-ot0-f177.google.com (HELO mail-ot0-f177.google.com) (74.125.82.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Apr 2018 20:03:16 +0000 Received: by mail-ot0-f177.google.com with SMTP id h55-v6so7405113ote.9 for ; Thu, 12 Apr 2018 13:03:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=jsganL0eTq1sDZ+uFYvbCBEYg1PGsi8z+yWQjdtb3Fk=; b=eRF3TI8CT++PLViovCJ0EEG9M9d/V/tu7Z+KA6sH2a6o1PnVf94k1dWaf31dHmZl2t 4TCOPzu+4IOUrJ5i3Nsrlsu24PllUq4HRtg0A0vz7n1UaZZ6FOb/F8JkBdJSVIeFk+Jc CNyHC8P3LhDvrQIgfpfjJrygKpDT84aWYt8pN97l26qrZ2JrMyTQAJ9lhO2vh3OaOtKt 0YxprbePqjr50xNrl3q58sEOA6V5SxOk3Ebk0pLgqtzOS7FyO0jJ85iZO1uwsH9eM2l4 UoJ1DHgYgMRuMmhmjNL4bb89b6DjJiVXNiqu4GekcL3ApLjMAmS+GYRlQABZsImI50Bh bV5Q== X-Gm-Message-State: ALQs6tDD1LOAqAd9Qltb2WATJMMC8g9ennZ4JF/WG50Pzb0ZOC8T1xSR myvvn6+Ka4d+VlKYzSQmlxMqlmeVUH3Z8aOH36Ewx75k X-Google-Smtp-Source: AIpwx49NVmWaqSKYr6Rg5FD6EKjfecowMaOCAQt0wkcyQi9mZMExHQtUJdXrQAG57aM4kRKMNzjNu58jGv3pykiGF4o= X-Received: by 2002:a9d:48eb:: with SMTP id a40-v6mr1741182otj.86.1523563394563; Thu, 12 Apr 2018 13:03:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.201.7.234 with HTTP; Thu, 12 Apr 2018 13:02:54 -0700 (PDT) From: Jason Merrill Date: Thu, 12 Apr 2018 16:02:54 -0400 Message-ID: Subject: C++ PATCH for c++/85356, C++17 ICE with pointer to member function in template To: gcc-patches List X-IsSubscribed: yes We weren't instantiating exception-specifications when a template referred to them, but that won't fly in the C++17 world where they're part of the type, so we need to resolve them to do overload resolution for non-dependent expressions. The change to check_redeclaration_exception_specification is necessary because type_dependent_expression_p (fn) will fail for a dependent new_decl, beacuse it doesn't have DECL_TEMPLATE_INFO yet. Tested x86_64-pc-linux-gnu, applying to trunk. commit e68e003bf7c837312bab52de2195ef4707150a3a Author: Jason Merrill Date: Thu Apr 12 07:45:03 2018 -0400 PR c++/85356 - ICE with pointer to member function. * pt.c (maybe_instantiate_noexcept): Do instantiate in templates if flag_noexcept_type. Build the new spec within the function context. * except.c (build_noexcept_spec): Do get constant value in templates if flag_noexcept_type. * decl.c (check_redeclaration_exception_specification): Don't instantiate noexcept on a dependent declaration. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 44a152bd195..9f1a171ead7 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -1232,8 +1232,11 @@ check_redeclaration_exception_specification (tree new_decl, && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions)) return; - maybe_instantiate_noexcept (new_decl); - maybe_instantiate_noexcept (old_decl); + if (!type_dependent_expression_p (old_decl)) + { + maybe_instantiate_noexcept (new_decl); + maybe_instantiate_noexcept (old_decl); + } new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl)); old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl)); diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 0b46698b974..6dab6d6bd96 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -1194,11 +1194,14 @@ build_noexcept_spec (tree expr, int complain) { /* This isn't part of the signature, so don't bother trying to evaluate it until instantiation. */ - if (!processing_template_decl && TREE_CODE (expr) != DEFERRED_NOEXCEPT) + if (TREE_CODE (expr) != DEFERRED_NOEXCEPT + && (!processing_template_decl + || (flag_noexcept_type && !value_dependent_expression_p (expr)))) { expr = perform_implicit_conversion_flags (boolean_type_node, expr, complain, LOOKUP_NORMAL); + expr = instantiate_non_dependent_expr (expr); expr = cxx_constant_value (expr); } if (TREE_CODE (expr) == INTEGER_CST) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 76e546cdeaa..da8a5264d33 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -23234,7 +23234,8 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) tree fntype, spec, noex, clone; /* Don't instantiate a noexcept-specification from template context. */ - if (processing_template_decl) + if (processing_template_decl + && (!flag_noexcept_type || type_dependent_expression_p (fn))) return true; if (DECL_CLONED_FUNCTION_P (fn)) @@ -23273,10 +23274,10 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) tf_warning_or_error, fn, /*function_p=*/false, /*integral_constant_expression_p=*/true); + spec = build_noexcept_spec (noex, tf_warning_or_error); pop_deferring_access_checks (); pop_access_scope (fn); pop_tinst_level (); - spec = build_noexcept_spec (noex, tf_warning_or_error); if (spec == error_mark_node) spec = noexcept_false_spec; } diff --git a/gcc/testsuite/g++.dg/template/mem_func_ptr2.C b/gcc/testsuite/g++.dg/template/mem_func_ptr2.C new file mode 100644 index 00000000000..9ceabd3642b --- /dev/null +++ b/gcc/testsuite/g++.dg/template/mem_func_ptr2.C @@ -0,0 +1,13 @@ +// PR c++/85356 + +struct A +{ + A& operator=(int); +}; + +void foo(A&(A::*)(int)); + +template void bar() +{ + foo(&A::operator=); +}