From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 45303 invoked by alias); 22 Nov 2018 23:40:19 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 45208 invoked by uid 89); 22 Nov 2018 23:40:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=visits, regresses, Hx-languages-length:4569, sk:integer X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Nov 2018 23:40:14 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B1BB750DC; Thu, 22 Nov 2018 23:40:13 +0000 (UTC) Received: from free.home (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B55256061E; Thu, 22 Nov 2018 23:40:12 +0000 (UTC) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTP id wAMNe4ps190362; Thu, 22 Nov 2018 21:40:04 -0200 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org Subject: [PATCH] [PR86397] set p_t_decl while canonicalizing eh specs for mangling Date: Thu, 22 Nov 2018 23:40:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2018-11/txt/msg01970.txt.bz2 Mangling visits the base template function type, prior to template resolution, and on such types, exception specifications may contain unresolved noexcept expressions. nothrow_spec_p is called on them even whe exception specifications are not part of function types, and it rejects unresolved noexcept expressions if processing_template_decl is not set. Setting processing_template_decl while mangling what is indeed the (generic) type of a function template would solve this problem, but it would cause others: no_linkage_check, for example, returns early if processing_template_decl, and this regresses g++.dg/pr79091.C and g++.dg/abi/no-linkage-expr1.C. So, instead of setting processing_template_decl throughout, I'm introducing another flag, processing_template_function_signature, and using it to set processing_template_decl only while canonicalizing the exception spec, which is where nothrow_spec_p gets called. Regstrapped on i686- and x86_64-linux-gnu. Ok to install? for gcc/cp/ChangeLog PR c++/86397 * mangle.c (processing_template_function_signature): New var. (write_encoding): Set it while mangling generic template type. (canonicalize_for_substitution): Set processing_template_decl while handling exception specs if processing_template_function_signature. for gcc/testsuite/ChangeLog PR c++/86397 * g++.dg/cpp0x/pr86397-1.C: New. * g++.dg/cpp0x/pr86397-2.C: New. --- gcc/cp/mangle.c | 19 +++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/pr86397-1.C | 4 ++++ gcc/testsuite/g++.dg/cpp0x/pr86397-2.C | 4 ++++ 3 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr86397-1.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr86397-2.C diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 64415894bc57..a499ef97b3c6 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -170,6 +170,17 @@ integer_type_codes[itk_none] =3D '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; =20 +/* Exception specifications may carry unresolved noexcept expressions + before template substitution, but nothrow_spec_p will fail an + assert check if it comes across such a spec while + !processing_template_decl. So, when we start processing the + signature of a template function, that may contain a such + unresolved expressions, we set this variable. Then, as we process + the exception spec, we set processing_template_decl. We don't want + to set processing_template_decl throughout, becuase this affects + other relevant tests, such as no_linkage_check. */ +static int processing_template_function_signature; + static int decl_is_template_id (const tree, tree* const); =20 /* Functions for handling substitutions. */ @@ -418,7 +429,11 @@ canonicalize_for_substitution (tree node) || TREE_CODE (node) =3D=3D METHOD_TYPE) { node =3D build_ref_qualified_type (node, type_memfn_rqual (orig)); + if (processing_template_function_signature) + processing_template_decl++; tree r =3D canonical_eh_spec (TYPE_RAISES_EXCEPTIONS (orig)); + if (processing_template_function_signature) + processing_template_decl--; if (flag_noexcept_type) node =3D build_exception_variant (node, r); else @@ -836,6 +851,7 @@ write_encoding (const tree decl) write_bare_function_type -- otherwise, it will get confused about which artificial parameters to skip. */ d =3D NULL_TREE; + ++processing_template_function_signature; } else { @@ -846,6 +862,9 @@ write_encoding (const tree decl) write_bare_function_type (fn_type, mangle_return_type_p (decl), d); + + if (tmpl) + --processing_template_function_signature; } } =20 diff --git a/gcc/testsuite/g++.dg/cpp0x/pr86397-1.C b/gcc/testsuite/g++.dg/= cpp0x/pr86397-1.C new file mode 100644 index 000000000000..4f9f5fa7e4c8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr86397-1.C @@ -0,0 +1,4 @@ +// { dg-do compile { target c++11 } } +void e(); +template void f(int() noexcept(e)) {} +template void f(int()); // { dg-error "does not match" "" { target = c++17 } } diff --git a/gcc/testsuite/g++.dg/cpp0x/pr86397-2.C b/gcc/testsuite/g++.dg/= cpp0x/pr86397-2.C new file mode 100644 index 000000000000..fb43499526e8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr86397-2.C @@ -0,0 +1,4 @@ +// { dg-do compile { target c++11 } } +void e(); +template void f(int() noexcept(e)) {} +template void f(int() noexcept); --=20 Alexandre Oliva, freedom fighter https://FSFLA.org/blogs/lxo Be the change, be Free! FSF Latin America board member GNU Toolchain Engineer Free Software Evangelist Hay que enGNUrecerse, pero sin perder la terGNUra jam=C3=A1s-GNUChe