From patchwork Wed Nov 15 18:03:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 165543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp2715366vqg; Wed, 15 Nov 2023 10:04:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBeMfC8NmtyEgQZsgEI6iFhPcsKjwSXSigXle0x8YuzYSX2S2hpGS3cCeGT9mS74rqq4eQ X-Received: by 2002:a05:622a:1703:b0:421:c3a9:1e4f with SMTP id h3-20020a05622a170300b00421c3a91e4fmr6815916qtk.7.1700071468735; Wed, 15 Nov 2023 10:04:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700071468; cv=pass; d=google.com; s=arc-20160816; b=sVDXUC0Ll80mKSV/4zZVxuSwfpbP1bYmHlr9A5Nw3Ea6o4ddCOQtP27dfgYFDLAGxn DjlP1WEzc9+YBY3C+ukbd1AwU5cNSWDbOndHUKbF086OELTLjUrrp1M8ZPXEET89fKZJ TcashX01Hz6Q+OndzOxb/hZWE1tDMPW51TFxvSzxMJheNlmTzvjILLvNFMhpfO8zo21a eoIhiFqqZ/BDgHqR0XCzaEf97EgveiaEq4RzYlouEBX/An78VKdboWSaJxvbG8i41m4e pITAKfRPpJ3Q8GNu3PweylcW+9XDKHBc4U7Ksc7PsPfYPbSUpPyRuTWMWsY4Yrd1Av0j szJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=JS2CUBKtnF2nZd4emmGDB29/jhf6yTGw28WeLWXaSRc=; fh=1Hi9m88IqcWZGtfSxUrMGG+GBgL26N02X1SANXM6iTs=; b=SDXxzvm7WURonacYz5NVdQTI50M9ojrcRAshpOtqsQ9bZy3wmuVay8FpeI/qJKgmhn gqsSkFfxVDSzPHl7d1lgZvSclwFcHF5rnrZPsgtI4BLMwhqni2+d1WFqSi8/o+ZO+6B1 g2CkztzECvuPd8B+UbgxZj3w+VAHXrkSPleH1dYoAKLrsNCOveTITw0nlK/c8YMTsQKC C3HHSfpLkQ4qGNBmty9634wtGqNjadkPCzMmX17h2dksjphM0Tht4eByz+aVTvMrgWiV x6zqYteYlhF4AOBsiR5qE2C6bnOQyRwUfy/C9GjNLRNJ8drwE4LbQw4h3+V+mRFGM7Nf 9/Yg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h5fFI3vG; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h22-20020ac87d56000000b004197d8cff5fsi9099851qtb.612.2023.11.15.10.04.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 10:04:28 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h5fFI3vG; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7AE123858C2D for ; Wed, 15 Nov 2023 18:04:28 +0000 (GMT) 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 1842B3858D20 for ; Wed, 15 Nov 2023 18:03:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1842B3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1842B3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700071445; cv=none; b=pFHrDTjY0KZRZD1pn0DTvbQDZ2gHQ8APwKaJK2/xzMD3dO86usLhDyx4IJlMRuansGZWiAxFR55annNq3rdn/EgXrm2ezi4UsBl0XDcWytOPy7tkdH4VEOJH4/zr3sQMmOXPPXc7gNWGYVMb+hR+XDeldfWeewuCBu2WFAhceHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700071445; c=relaxed/simple; bh=340bPnlvYGSy9Y8CsP7YYsbA4xnbk6fh82l1to9vZ4w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tmXF4gFcMEwT3y6VLcWfgDcTkrqtzQ2WHv9iHWQNvlDsGpx9uHme8Jvkte6/LgOegMEDrsEcp5pknolW5Oz0+rftth//Z7/zu4JUvfoMEit5/cZ80fCDu0X73RxSCW8BKCgMZN5KOg5mOAzBy5Txwahwnk9z3wSVagcen/08v5c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700071434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JS2CUBKtnF2nZd4emmGDB29/jhf6yTGw28WeLWXaSRc=; b=h5fFI3vG7LA4AlFKu5WKJ4ZNqFtUletnv5wWAI3lX551936sqJZE9s+vJKKc0r2Jk9+hLQ B0BwkdFz7MKO3Rv8WXrXkQNfn+KdrrByJIME7x9DhCxt1JrC5kdhqF6pJQzio8Td3hEHd/ LetH1asMfAV75lVFDKmgxo0Gzrpb+fw= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-0jMzM4QwPjKOMj11sI6uEA-1; Wed, 15 Nov 2023 13:03:53 -0500 X-MC-Unique: 0jMzM4QwPjKOMj11sI6uEA-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-67445c67d5dso81653506d6.2 for ; Wed, 15 Nov 2023 10:03:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700071432; x=1700676232; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JS2CUBKtnF2nZd4emmGDB29/jhf6yTGw28WeLWXaSRc=; b=fOjuk2Sm8pNJP/Fk9GFjnfU+waDj4zBtYw2B9No5u9A5Re7bXof0NwnHEkzhKt4KL/ Z+RwAqbsIiHcV0srjsyzBbqJpY4Ixp8H7ZDUMFF+aRbMADUzsttP0cFld9/zke9mqtw/ k1IFW/FUW2Tdd39dH2Qhi2VNUQWcP3VmEP8ztH/zeZi/QcPalinC8/8MxcVQeKOCWU+4 KrFyin8ibQiqPP85IyA/PXHqKAm1q2f/Gzhf8UPCCauFBMWQKaZYkbfrS93OQQEktG6R 2+mT9gttsZ6tclTTpo5jMw8PmS2n4njQ2Lhzo0OhVgedtDs2DThnS9yi2U5FhHaMCJE+ J7tQ== X-Gm-Message-State: AOJu0YxHVp8tM0GXP38nU0CV1Shpnnkr60LHR8q8wdqfgXuLQplpETGm OPmy9JhKLcoUTZ7tesPBeBgc9BcjkYgzkAiADUray9n6A87cGLkpt25V3ifyuuoZeqENzTOVYPL FzZ2GwBXWzs2cU18S3/gm2MGilS70hWmLl1i8f1aZvCDL4H5Ro2kboZjy9O/oN2y+x3+J+mCbtb I= X-Received: by 2002:ad4:50cf:0:b0:672:587:731 with SMTP id e15-20020ad450cf000000b0067205870731mr6513808qvq.28.1700071432405; Wed, 15 Nov 2023 10:03:52 -0800 (PST) X-Received: by 2002:ad4:50cf:0:b0:672:587:731 with SMTP id e15-20020ad450cf000000b0067205870731mr6513769qvq.28.1700071432007; Wed, 15 Nov 2023 10:03:52 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id s10-20020a0cf64a000000b00668bb8be252sm701915qvm.60.2023.11.15.10.03.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 10:03:51 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: constantness of call to function pointer [PR111703] Date: Wed, 15 Nov 2023 13:03:49 -0500 Message-ID: <20231115180350.2126787-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.rc1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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_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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782654140218946145 X-GMAIL-MSGID: 1782654140218946145 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/13/12 (to match the PR107939 / r13-6525-ge09bc034d1b4d6 backports)? -- >8 -- potential_constant_expression for a CALL_EXPR to a non-overload tests FUNCTION_POINTER_TYPE_P on the callee rather than on the type of the callee, which means we always pass want_rval=any when recursing and so may fail to properly treat a non-constant function pointer callee as such. Fixing this turns out to further work around the PR111703 issue. PR c++/111703 PR c++/107939 gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1) : Fix FUNCTION_POINTER_TYPE_P test. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-fn8.C: Extend test. * g++.dg/diagnostic/constexpr4.C: New test. --- gcc/cp/constexpr.cc | 4 +++- gcc/testsuite/g++.dg/cpp2a/concepts-fn8.C | 2 ++ gcc/testsuite/g++.dg/diagnostic/constexpr4.C | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/constexpr4.C diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 8a6b210144a..5ecc30117a1 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -9547,7 +9547,9 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, } else if (fun) { - if (RECUR (fun, FUNCTION_POINTER_TYPE_P (fun) ? rval : any)) + if (RECUR (fun, (TREE_TYPE (fun) + && FUNCTION_POINTER_TYPE_P (TREE_TYPE (fun)) + ? rval : any))) /* Might end up being a constant function pointer. But it could also be a function object with constexpr op(), so we pass 'any' so that the underlying VAR_DECL is deemed diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-fn8.C b/gcc/testsuite/g++.dg/cpp2a/concepts-fn8.C index 3f63a5b28d7..c63d26c931d 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-fn8.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-fn8.C @@ -15,10 +15,12 @@ struct P { }; void (*f)(P); +P (*h)(P); template constexpr bool g() { P x; f(x); // { dg-bogus "from here" } + f(h(x)); // { dg-bogus "from here" } return true; } diff --git a/gcc/testsuite/g++.dg/diagnostic/constexpr4.C b/gcc/testsuite/g++.dg/diagnostic/constexpr4.C new file mode 100644 index 00000000000..f971f533b08 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/constexpr4.C @@ -0,0 +1,9 @@ +// Verify we diagnose a call to a non-constant function pointer ahead of time. +// { dg-do compile { target c++11 } } + +int (*f)(int); + +template +void g() { + static_assert(f(N) == 0, ""); // { dg-error "non-constant|'f' is not usable" } +}