Message ID | 20220913114538.2741902-1-ppalka@redhat.com |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp2309065wrt; Tue, 13 Sep 2022 04:46:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR6w4OZkRTtPlOsPqVYVehGOCcfSUVxUJc8DK6C+fZzIt+mgwQx+07gPdNZVA636Q8cANTLK X-Received: by 2002:a17:906:cc0e:b0:77c:d77:576d with SMTP id ml14-20020a170906cc0e00b0077c0d77576dmr8925481ejb.658.1663069591347; Tue, 13 Sep 2022 04:46:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663069591; cv=none; d=google.com; s=arc-20160816; b=jyiXn3d2GGv91EyI6kcHjAPh5hFvxRmIx9M0bGB94gesG3c4nUB6TNS/gVSen1OmhL dItfx4nR63uUP1eO2E9/KFhuVhfCB2+YttUixd2puvrslI+UGozq7+YX1sI0oYU0aFVf z6u8uDXdgo4KPRlT4DLqSkY3LVWE6u/CvXkyfrl/h/V6vw2hGo4rMfdT9KN3m9QDBT+C TY6/VwYHnjrZSE/bhQbldaNAcjryzcuZbW7NxYtBhEbEvvktYMYfujYpgWhWAFq94QiK BuJ7qYal4YgluvKiT8xlwdTab9PCDEgmdpz+aoNTiUoVaglMzO8i53o/4MZ3Mdpp9+BZ vduA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=x83+eGX6VhN32JnwVfJ0y+C9YDMJttKQgeBu8ZVx/uM=; b=j9NYUuiW5C3v0UyfwRySDT3jWWCv0c14OZDVxByM6ayK752iMjLtZKb8nBvwsoHikQ IPPuV265pwJ6x/OGTYIYDS9CG1+xR3YawRKmvjlpXGqWmh8p9EN+uEfthovRLcrVLflr UAILRvFnxAFhQjsUhfMN6QH3IxUBE6qiw7wDY5JT+9lgwhpP1h7IV1tw1AtZjVqKE0Ka Pv3ZACsEjzh526u5kYVoYcLKZeUn25Bi5zTV79n+xmw4/RM6/CjGpnf6FZGqO/epi51X n4b9iHR+Vn78ZqpRWsOw+rLk0mNXSIL1Yi4h1l1O7ZjF3hNXTHTbfv99VluHOs4AIlm7 RAhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LuR2896V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u12-20020a50a40c000000b0044f0eedd1d7si8826666edb.438.2022.09.13.04.46.31 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 04:46:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LuR2896V; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA486385C420 for <ouuuleilei@gmail.com>; Tue, 13 Sep 2022 11:46:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA486385C420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663069589; bh=x83+eGX6VhN32JnwVfJ0y+C9YDMJttKQgeBu8ZVx/uM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LuR2896VVhRPRPbdQbPlnuw1Wm/iywddDuBTXahEtv06RA87w+KsMS4uF8dMIXPGC AG+SKeTLPMxKtIKynHB9Rzd+S2U8+gyxlcm9mgE23NIo55A0eoCQfwMp34LeJRVsmD SE+XWhRZuA7YxMYzj2Pp5jbsa9QpBeMvhPNjxdaE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id AC4263856DD6 for <gcc-patches@gcc.gnu.org>; Tue, 13 Sep 2022 11:45:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AC4263856DD6 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-278-GJk949AmMiqpPaXmkj7Yww-1; Tue, 13 Sep 2022 07:45:43 -0400 X-MC-Unique: GJk949AmMiqpPaXmkj7Yww-1 Received: by mail-qk1-f198.google.com with SMTP id h8-20020a05620a284800b006b5c98f09fbso9999797qkp.21 for <gcc-patches@gcc.gnu.org>; Tue, 13 Sep 2022 04:45:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=x83+eGX6VhN32JnwVfJ0y+C9YDMJttKQgeBu8ZVx/uM=; b=oisrNa1cUsQ8JSkKaHkCPFRXwiNru68yfp+jqnZfHytuWD6jSQQZVyckSI3BxE/CZ1 pqAh5Ao8ZVC+14vtaW9Pa3sD/75Xy9RKdc07uVR98HtDiCBIvwH9uC7LVJ/NEdnM+5/x 8qLPkwygL3/6LANxivfwY9zUc8RJsY0V5fbQyHjb9pqx5O6YHhIGUDkGpKmbjBYWlH+w ajNW8kgXFplj2fK0tiXAmvzX8Tzg6Wf6L+YHAHMR8mEDjncZ4YFfKL25dEPsTY9s+3VF g02Lwt8h7QrHwtnr1r5UHpwxjab5Kusa8/Ch3UD/LrLYcgyexipTWjbKX6kZnLtVYLhH /z/A== X-Gm-Message-State: ACgBeo1OsD8X4iN9m8MV34FFjg8eTw2S+nYJDsrXBAVvuZ0Tl72e5FkN RTIQD2H0ZDNqHXyrLX3wHw6XaxxxuXZlTZOPeo9tvB1K/s3ooAZGL5QT9XdjMj240R4vEqVg8b2 HJNs3OBCO89VVYelzpu6a+3oR7C8F17R28+akzspnndEbJOW0RcwgyfdHRaW0ceDAlzA= X-Received: by 2002:a05:620a:ed0:b0:6cb:eb81:e039 with SMTP id x16-20020a05620a0ed000b006cbeb81e039mr15323435qkm.622.1663069542715; Tue, 13 Sep 2022 04:45:42 -0700 (PDT) X-Received: by 2002:a05:620a:ed0:b0:6cb:eb81:e039 with SMTP id x16-20020a05620a0ed000b006cbeb81e039mr15323410qkm.622.1663069542351; Tue, 13 Sep 2022 04:45:42 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id o11-20020ac8698b000000b00342f844e30fsm8447554qtq.31.2022.09.13.04.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 04:45:41 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: some missing-SFINAE fixes Date: Tue, 13 Sep 2022 07:45:38 -0400 Message-Id: <20220913114538.2741902-1-ppalka@redhat.com> X-Mailer: git-send-email 2.37.3.542.gdd3f6c4cae MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.4 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Patrick Palka via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Patrick Palka <ppalka@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743854859745951345?= X-GMAIL-MSGID: =?utf-8?q?1743854859745951345?= |
Series |
c++: some missing-SFINAE fixes
|
|
Commit Message
Patrick Palka
Sept. 13, 2022, 11:45 a.m. UTC
It looks like we aren't respecting SFINAE for: * an invalid/non-constant conditional explicit-specifier * a non-constant conditional noexcept-specifier * a non-constant argument to __integer_pack This patch fixes these issues in the usual way, by passing complain and propagating error_mark_node appropriately. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: * decl.cc (build_explicit_specifier): Pass complain to cxx_constant_value. * except.cc (build_noexcept_spec): Likewise. * pt.cc (expand_integer_pack): Likewise. (tsubst_function_decl): Propagate error_mark_node returned from build_explicit_specifier. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/noexcept-type26.C: New test. * g++.dg/cpp2a/explicit19.C: New test. * g++.dg/ext/integer-pack6.C: New test. --- gcc/cp/decl.cc | 2 +- gcc/cp/except.cc | 2 +- gcc/cp/pt.cc | 6 ++++-- gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C | 12 ++++++++++++ gcc/testsuite/g++.dg/cpp2a/explicit19.C | 12 ++++++++++++ gcc/testsuite/g++.dg/ext/integer-pack6.C | 13 +++++++++++++ 6 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/explicit19.C create mode 100644 gcc/testsuite/g++.dg/ext/integer-pack6.C
Comments
On 9/13/22 07:45, Patrick Palka wrote: > It looks like we aren't respecting SFINAE for: > > * an invalid/non-constant conditional explicit-specifier > * a non-constant conditional noexcept-specifier > * a non-constant argument to __integer_pack > > This patch fixes these issues in the usual way, by passing complain > and propagating error_mark_node appropriately. > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? > > gcc/cp/ChangeLog: > > * decl.cc (build_explicit_specifier): Pass complain to > cxx_constant_value. > * except.cc (build_noexcept_spec): Likewise. > * pt.cc (expand_integer_pack): Likewise. > (tsubst_function_decl): Propagate error_mark_node returned > from build_explicit_specifier. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp1z/noexcept-type26.C: New test. > * g++.dg/cpp2a/explicit19.C: New test. > * g++.dg/ext/integer-pack6.C: New test. > --- > gcc/cp/decl.cc | 2 +- > gcc/cp/except.cc | 2 +- > gcc/cp/pt.cc | 6 ++++-- > gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C | 12 ++++++++++++ > gcc/testsuite/g++.dg/cpp2a/explicit19.C | 12 ++++++++++++ > gcc/testsuite/g++.dg/ext/integer-pack6.C | 13 +++++++++++++ > 6 files changed, 43 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C > create mode 100644 gcc/testsuite/g++.dg/cpp2a/explicit19.C > create mode 100644 gcc/testsuite/g++.dg/ext/integer-pack6.C > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index 936f1cf0197..5404d7e084c 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -18557,7 +18557,7 @@ build_explicit_specifier (tree expr, tsubst_flags_t complain) > > expr = build_converted_constant_bool_expr (expr, complain); > expr = instantiate_non_dependent_expr (expr, complain); > - expr = cxx_constant_value (expr); > + expr = cxx_constant_value (expr, NULL_TREE, complain); The patch is OK, but perhaps we want another overload that omits the object parameter? > return expr; > } > > diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc > index 7fdbc747c22..4d7f0ce102d 100644 > --- a/gcc/cp/except.cc > +++ b/gcc/cp/except.cc > @@ -1257,7 +1257,7 @@ build_noexcept_spec (tree expr, tsubst_flags_t complain) > { > expr = build_converted_constant_bool_expr (expr, complain); > expr = instantiate_non_dependent_expr (expr, complain); > - expr = cxx_constant_value (expr); > + expr = cxx_constant_value (expr, NULL_TREE, complain); > } > if (TREE_CODE (expr) == INTEGER_CST) > { > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 1c6f4b84612..f16f5ffca20 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -3869,7 +3869,7 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain, > else > { > hi = instantiate_non_dependent_expr (hi, complain); > - hi = cxx_constant_value (hi); > + hi = cxx_constant_value (hi, NULL_TREE, complain); > int len = valid_constant_size_p (hi) ? tree_to_shwi (hi) : -1; > > /* Calculate the largest value of len that won't make the size of the vec > @@ -14312,7 +14312,9 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, > /*function_p=*/false, > /*i_c_e_p=*/true); > spec = build_explicit_specifier (spec, complain); > - if (instantiation_dependent_expression_p (spec)) > + if (spec == error_mark_node) > + return error_mark_node; > + else if (instantiation_dependent_expression_p (spec)) > store_explicit_specifier (r, spec); > else > { > diff --git a/gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C b/gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C > new file mode 100644 > index 00000000000..73058395f0a > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C > @@ -0,0 +1,12 @@ > +// Verify a non-constant conditional noexcept-specifier of a function type > +// is a SFINAE error. > +// { dg-do compile { target c++17 } } > + > +template<class T> void f(void() noexcept(T::value)) = delete; > +template<class T> void f(...); > + > +struct B { static bool value; }; > + > +int main() { > + f<B>(nullptr); > +} > diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit19.C b/gcc/testsuite/g++.dg/cpp2a/explicit19.C > new file mode 100644 > index 00000000000..47903813680 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/explicit19.C > @@ -0,0 +1,12 @@ > +// Verify a conditional explicit-specifier is a SFINAE context. > +// { dg-do compile { target c++20 } } > + > +struct A { > + template<class T> explicit(T::value) A(T) = delete; > + A(...); > +}; > + > +struct B { static bool value; }; > + > +A x(0); > +A y(B{}); > diff --git a/gcc/testsuite/g++.dg/ext/integer-pack6.C b/gcc/testsuite/g++.dg/ext/integer-pack6.C > new file mode 100644 > index 00000000000..7e16bc44b40 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/ext/integer-pack6.C > @@ -0,0 +1,13 @@ > +// Verify a non-constant argument to __integer_pack is a SFINAE error. > +// { dg-do compile { target c++11 } } > + > +template<int...> struct A { }; > + > +template<class T> auto f(int) -> A<__integer_pack(T::value)...> = delete; > +template<class T> void f(...); > + > +struct B { static int value; }; > + > +int main() { > + f<B>(0); > +}
On Tue, 13 Sep 2022, Jason Merrill wrote: > On 9/13/22 07:45, Patrick Palka wrote: > > It looks like we aren't respecting SFINAE for: > > > > * an invalid/non-constant conditional explicit-specifier > > * a non-constant conditional noexcept-specifier > > * a non-constant argument to __integer_pack > > > > This patch fixes these issues in the usual way, by passing complain > > and propagating error_mark_node appropriately. > > > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > > trunk? > > > > gcc/cp/ChangeLog: > > > > * decl.cc (build_explicit_specifier): Pass complain to > > cxx_constant_value. > > * except.cc (build_noexcept_spec): Likewise. > > * pt.cc (expand_integer_pack): Likewise. > > (tsubst_function_decl): Propagate error_mark_node returned > > from build_explicit_specifier. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/cpp1z/noexcept-type26.C: New test. > > * g++.dg/cpp2a/explicit19.C: New test. > > * g++.dg/ext/integer-pack6.C: New test. > > --- > > gcc/cp/decl.cc | 2 +- > > gcc/cp/except.cc | 2 +- > > gcc/cp/pt.cc | 6 ++++-- > > gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C | 12 ++++++++++++ > > gcc/testsuite/g++.dg/cpp2a/explicit19.C | 12 ++++++++++++ > > gcc/testsuite/g++.dg/ext/integer-pack6.C | 13 +++++++++++++ > > 6 files changed, 43 insertions(+), 4 deletions(-) > > create mode 100644 gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C > > create mode 100644 gcc/testsuite/g++.dg/cpp2a/explicit19.C > > create mode 100644 gcc/testsuite/g++.dg/ext/integer-pack6.C > > > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > > index 936f1cf0197..5404d7e084c 100644 > > --- a/gcc/cp/decl.cc > > +++ b/gcc/cp/decl.cc > > @@ -18557,7 +18557,7 @@ build_explicit_specifier (tree expr, tsubst_flags_t > > complain) > > expr = build_converted_constant_bool_expr (expr, complain); > > expr = instantiate_non_dependent_expr (expr, complain); > > - expr = cxx_constant_value (expr); > > + expr = cxx_constant_value (expr, NULL_TREE, complain); > > The patch is OK, but perhaps we want another overload that omits the object > parameter? Thanks -- sounds good, like the following incremental patch? -- >8 -- Subject: [PATCH] c++: two-parameter version of cxx_constant_value Since some callers need the complain parameter but not the object parameter, let's introduce and use an overload of cxx_constant_value that omits the latter. gcc/cp/ChangeLog: * cp-tree.h (cxx_constant_value): Define two-parameter version that omits the object parameter. * decl.cc (build_explicit_specifier): Omit NULL_TREE object argument to cxx_constant_value. * except.cc (build_noexcept_spec): Likewise. * pt.cc (expand_integer_pack): Likewise. (fold_targs_r): Likewise. * semantics.cc (finish_if_stmt_cond): Likewise. --- gcc/cp/cp-tree.h | 2 ++ gcc/cp/decl.cc | 2 +- gcc/cp/except.cc | 2 +- gcc/cp/pt.cc | 4 ++-- gcc/cp/semantics.cc | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 2ba44e80e20..1eb176d4a50 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8414,6 +8414,8 @@ extern bool require_rvalue_constant_expression (tree); extern bool require_potential_rvalue_constant_expression (tree); extern tree cxx_constant_value (tree, tree = NULL_TREE, tsubst_flags_t = tf_error); +inline tree cxx_constant_value (tree t, tsubst_flags_t complain) +{ return cxx_constant_value (t, NULL_TREE, complain); } extern void cxx_constant_dtor (tree, tree); extern tree cxx_constant_init (tree, tree = NULL_TREE); extern tree maybe_constant_value (tree, tree = NULL_TREE, bool = false); diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 5404d7e084c..006e9affcba 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -18557,7 +18557,7 @@ build_explicit_specifier (tree expr, tsubst_flags_t complain) expr = build_converted_constant_bool_expr (expr, complain); expr = instantiate_non_dependent_expr (expr, complain); - expr = cxx_constant_value (expr, NULL_TREE, complain); + expr = cxx_constant_value (expr, complain); return expr; } diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc index 4d7f0ce102d..048612de400 100644 --- a/gcc/cp/except.cc +++ b/gcc/cp/except.cc @@ -1257,7 +1257,7 @@ build_noexcept_spec (tree expr, tsubst_flags_t complain) { expr = build_converted_constant_bool_expr (expr, complain); expr = instantiate_non_dependent_expr (expr, complain); - expr = cxx_constant_value (expr, NULL_TREE, complain); + expr = cxx_constant_value (expr, complain); } if (TREE_CODE (expr) == INTEGER_CST) { diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 074179288b6..db4e808adec 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -3869,7 +3869,7 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain, else { hi = instantiate_non_dependent_expr (hi, complain); - hi = cxx_constant_value (hi, NULL_TREE, complain); + hi = cxx_constant_value (hi, complain); int len = valid_constant_size_p (hi) ? tree_to_shwi (hi) : -1; /* Calculate the largest value of len that won't make the size of the vec @@ -20121,7 +20121,7 @@ fold_targs_r (tree targs, tsubst_flags_t complain) && !glvalue_p (elt) && !TREE_CONSTANT (elt)) { - elt = cxx_constant_value (elt, NULL_TREE, complain); + elt = cxx_constant_value (elt, complain); if (elt == error_mark_node) return false; } diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 3edefb2fca2..4f189978484 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -1042,7 +1042,7 @@ finish_if_stmt_cond (tree orig_cond, tree if_stmt) { maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/true); cond = instantiate_non_dependent_expr (cond); - cond = cxx_constant_value (cond, NULL_TREE); + cond = cxx_constant_value (cond); } else {
On 9/13/22 09:46, Patrick Palka wrote: > On Tue, 13 Sep 2022, Jason Merrill wrote: > >> On 9/13/22 07:45, Patrick Palka wrote: >>> It looks like we aren't respecting SFINAE for: >>> >>> * an invalid/non-constant conditional explicit-specifier >>> * a non-constant conditional noexcept-specifier >>> * a non-constant argument to __integer_pack >>> >>> This patch fixes these issues in the usual way, by passing complain >>> and propagating error_mark_node appropriately. >>> >>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for >>> trunk? >>> >>> gcc/cp/ChangeLog: >>> >>> * decl.cc (build_explicit_specifier): Pass complain to >>> cxx_constant_value. >>> * except.cc (build_noexcept_spec): Likewise. >>> * pt.cc (expand_integer_pack): Likewise. >>> (tsubst_function_decl): Propagate error_mark_node returned >>> from build_explicit_specifier. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/cpp1z/noexcept-type26.C: New test. >>> * g++.dg/cpp2a/explicit19.C: New test. >>> * g++.dg/ext/integer-pack6.C: New test. >>> --- >>> gcc/cp/decl.cc | 2 +- >>> gcc/cp/except.cc | 2 +- >>> gcc/cp/pt.cc | 6 ++++-- >>> gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C | 12 ++++++++++++ >>> gcc/testsuite/g++.dg/cpp2a/explicit19.C | 12 ++++++++++++ >>> gcc/testsuite/g++.dg/ext/integer-pack6.C | 13 +++++++++++++ >>> 6 files changed, 43 insertions(+), 4 deletions(-) >>> create mode 100644 gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C >>> create mode 100644 gcc/testsuite/g++.dg/cpp2a/explicit19.C >>> create mode 100644 gcc/testsuite/g++.dg/ext/integer-pack6.C >>> >>> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc >>> index 936f1cf0197..5404d7e084c 100644 >>> --- a/gcc/cp/decl.cc >>> +++ b/gcc/cp/decl.cc >>> @@ -18557,7 +18557,7 @@ build_explicit_specifier (tree expr, tsubst_flags_t >>> complain) >>> expr = build_converted_constant_bool_expr (expr, complain); >>> expr = instantiate_non_dependent_expr (expr, complain); >>> - expr = cxx_constant_value (expr); >>> + expr = cxx_constant_value (expr, NULL_TREE, complain); >> >> The patch is OK, but perhaps we want another overload that omits the object >> parameter? > > Thanks -- sounds good, like the following incremental patch? OK. > -- >8 -- > > Subject: [PATCH] c++: two-parameter version of cxx_constant_value > > Since some callers need the complain parameter but not the object > parameter, let's introduce and use an overload of cxx_constant_value > that omits the latter. > > gcc/cp/ChangeLog: > > * cp-tree.h (cxx_constant_value): Define two-parameter version > that omits the object parameter. > * decl.cc (build_explicit_specifier): Omit NULL_TREE object > argument to cxx_constant_value. > * except.cc (build_noexcept_spec): Likewise. > * pt.cc (expand_integer_pack): Likewise. > (fold_targs_r): Likewise. > * semantics.cc (finish_if_stmt_cond): Likewise. > --- > gcc/cp/cp-tree.h | 2 ++ > gcc/cp/decl.cc | 2 +- > gcc/cp/except.cc | 2 +- > gcc/cp/pt.cc | 4 ++-- > gcc/cp/semantics.cc | 2 +- > 5 files changed, 7 insertions(+), 5 deletions(-) > > diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h > index 2ba44e80e20..1eb176d4a50 100644 > --- a/gcc/cp/cp-tree.h > +++ b/gcc/cp/cp-tree.h > @@ -8414,6 +8414,8 @@ extern bool require_rvalue_constant_expression (tree); > extern bool require_potential_rvalue_constant_expression (tree); > extern tree cxx_constant_value (tree, tree = NULL_TREE, > tsubst_flags_t = tf_error); > +inline tree cxx_constant_value (tree t, tsubst_flags_t complain) > +{ return cxx_constant_value (t, NULL_TREE, complain); } > extern void cxx_constant_dtor (tree, tree); > extern tree cxx_constant_init (tree, tree = NULL_TREE); > extern tree maybe_constant_value (tree, tree = NULL_TREE, bool = false); > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index 5404d7e084c..006e9affcba 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -18557,7 +18557,7 @@ build_explicit_specifier (tree expr, tsubst_flags_t complain) > > expr = build_converted_constant_bool_expr (expr, complain); > expr = instantiate_non_dependent_expr (expr, complain); > - expr = cxx_constant_value (expr, NULL_TREE, complain); > + expr = cxx_constant_value (expr, complain); > return expr; > } > > diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc > index 4d7f0ce102d..048612de400 100644 > --- a/gcc/cp/except.cc > +++ b/gcc/cp/except.cc > @@ -1257,7 +1257,7 @@ build_noexcept_spec (tree expr, tsubst_flags_t complain) > { > expr = build_converted_constant_bool_expr (expr, complain); > expr = instantiate_non_dependent_expr (expr, complain); > - expr = cxx_constant_value (expr, NULL_TREE, complain); > + expr = cxx_constant_value (expr, complain); > } > if (TREE_CODE (expr) == INTEGER_CST) > { > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 074179288b6..db4e808adec 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -3869,7 +3869,7 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain, > else > { > hi = instantiate_non_dependent_expr (hi, complain); > - hi = cxx_constant_value (hi, NULL_TREE, complain); > + hi = cxx_constant_value (hi, complain); > int len = valid_constant_size_p (hi) ? tree_to_shwi (hi) : -1; > > /* Calculate the largest value of len that won't make the size of the vec > @@ -20121,7 +20121,7 @@ fold_targs_r (tree targs, tsubst_flags_t complain) > && !glvalue_p (elt) > && !TREE_CONSTANT (elt)) > { > - elt = cxx_constant_value (elt, NULL_TREE, complain); > + elt = cxx_constant_value (elt, complain); > if (elt == error_mark_node) > return false; > } > diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc > index 3edefb2fca2..4f189978484 100644 > --- a/gcc/cp/semantics.cc > +++ b/gcc/cp/semantics.cc > @@ -1042,7 +1042,7 @@ finish_if_stmt_cond (tree orig_cond, tree if_stmt) > { > maybe_warn_for_constant_evaluated (cond, /*constexpr_if=*/true); > cond = instantiate_non_dependent_expr (cond); > - cond = cxx_constant_value (cond, NULL_TREE); > + cond = cxx_constant_value (cond); > } > else > {
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 936f1cf0197..5404d7e084c 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -18557,7 +18557,7 @@ build_explicit_specifier (tree expr, tsubst_flags_t complain) expr = build_converted_constant_bool_expr (expr, complain); expr = instantiate_non_dependent_expr (expr, complain); - expr = cxx_constant_value (expr); + expr = cxx_constant_value (expr, NULL_TREE, complain); return expr; } diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc index 7fdbc747c22..4d7f0ce102d 100644 --- a/gcc/cp/except.cc +++ b/gcc/cp/except.cc @@ -1257,7 +1257,7 @@ build_noexcept_spec (tree expr, tsubst_flags_t complain) { expr = build_converted_constant_bool_expr (expr, complain); expr = instantiate_non_dependent_expr (expr, complain); - expr = cxx_constant_value (expr); + expr = cxx_constant_value (expr, NULL_TREE, complain); } if (TREE_CODE (expr) == INTEGER_CST) { diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1c6f4b84612..f16f5ffca20 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -3869,7 +3869,7 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain, else { hi = instantiate_non_dependent_expr (hi, complain); - hi = cxx_constant_value (hi); + hi = cxx_constant_value (hi, NULL_TREE, complain); int len = valid_constant_size_p (hi) ? tree_to_shwi (hi) : -1; /* Calculate the largest value of len that won't make the size of the vec @@ -14312,7 +14312,9 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, /*function_p=*/false, /*i_c_e_p=*/true); spec = build_explicit_specifier (spec, complain); - if (instantiation_dependent_expression_p (spec)) + if (spec == error_mark_node) + return error_mark_node; + else if (instantiation_dependent_expression_p (spec)) store_explicit_specifier (r, spec); else { diff --git a/gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C b/gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C new file mode 100644 index 00000000000..73058395f0a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/noexcept-type26.C @@ -0,0 +1,12 @@ +// Verify a non-constant conditional noexcept-specifier of a function type +// is a SFINAE error. +// { dg-do compile { target c++17 } } + +template<class T> void f(void() noexcept(T::value)) = delete; +template<class T> void f(...); + +struct B { static bool value; }; + +int main() { + f<B>(nullptr); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit19.C b/gcc/testsuite/g++.dg/cpp2a/explicit19.C new file mode 100644 index 00000000000..47903813680 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/explicit19.C @@ -0,0 +1,12 @@ +// Verify a conditional explicit-specifier is a SFINAE context. +// { dg-do compile { target c++20 } } + +struct A { + template<class T> explicit(T::value) A(T) = delete; + A(...); +}; + +struct B { static bool value; }; + +A x(0); +A y(B{}); diff --git a/gcc/testsuite/g++.dg/ext/integer-pack6.C b/gcc/testsuite/g++.dg/ext/integer-pack6.C new file mode 100644 index 00000000000..7e16bc44b40 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/integer-pack6.C @@ -0,0 +1,13 @@ +// Verify a non-constant argument to __integer_pack is a SFINAE error. +// { dg-do compile { target c++11 } } + +template<int...> struct A { }; + +template<class T> auto f(int) -> A<__integer_pack(T::value)...> = delete; +template<class T> void f(...); + +struct B { static int value; }; + +int main() { + f<B>(0); +}