From patchwork Mon Dec 4 23:41:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 81304 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B8B23953834 for ; Mon, 4 Dec 2023 23:44:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 9837A3860760 for ; Mon, 4 Dec 2023 23:43:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9837A3860760 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9837A3860760 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701733449; cv=none; b=AjRqlRPquhOaVlw6CSsw+ns00cKHpGEruOCCQHXJLB2QX43qd7EMbxLCp63sKSUBW0Tbk3McelE/hoei+ep/siVyzB/yK/p7GsgpYcctkVsQe33J4hvRXE8yYh7sgm3dWUEdg/hiYThkTj4kCqOhy8TXq72yCWRu5d8iFQ8aIeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701733449; c=relaxed/simple; bh=pk7HcMS7gtCo6b8aYHs/0LGJ/H1XWfK4UDuamy7Yw4I=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=jWcjTN+PAs1l9i+qtsXJT90Vi45MU2AFpEyVPo2QoEwK3nS7w8t1YnberUy3EY8DVOWRmWn1snMDDAtyqN1T3udvKY+rI3glj4Qntn12CZn0Z5Fu0siyrLj6ZIEjU9YYpAri/HYafFIT0I51Ga6Lhdbucg5K1gctmsePfWwTqZY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rAIbR-0000t6-RH for gcc-patches@gcc.gnu.org; Mon, 04 Dec 2023 18:43:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701733304; 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=9iKSdByYwiONbe3/qg/dQROEBcl3kA4D6H+F3ntewH0=; b=JCpAmS6+R3oLrbj5JSlqI2KQghkLle9eYHivqRAkI4v9XrA8smCMe2ylBqjy/ReN1msRb6 J5tGehL7uHS2cK15SO4ujSKVhc1YxQf6Mq1B3iHOGv2ZuLz5jaW95fR1enMz/EC6+Tz53x j3hdu+XExRWS91jXJX+bSm0wU8wHpeE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701733431; 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=9iKSdByYwiONbe3/qg/dQROEBcl3kA4D6H+F3ntewH0=; b=ZMFaRd2UFSZI935MPKJ2ZkOi3ezeaU4gLZdLN+LHB8YiC9sUCLaGMwDIP1BwKllkPdn51D I/XIIcCuucZwHekDful/FkSXjbGP8XUP7nQGeb4pqYreNY3epJwKZDQpNp2r4p8vUbjeIn qzLJPaJPSfWOFox4/1pLkNJAW0BfDc8= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-551-j2M1odXCPj2HbiSQ6cQAhw-1; Mon, 04 Dec 2023 18:41:33 -0500 X-MC-Unique: j2M1odXCPj2HbiSQ6cQAhw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4256444b44eso4592471cf.2 for ; Mon, 04 Dec 2023 15:41:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701733293; x=1702338093; 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=9iKSdByYwiONbe3/qg/dQROEBcl3kA4D6H+F3ntewH0=; b=ZHuoydg5MU4pnahkVvQDAHWJPBKRA9a5Kiypejomi9nrji/XIdZW7nrd+L/SEoUiyR QnJNERko6KY5NXMrh3oJnVR2TAb1F+9C2Q9xXtG8zu560WCRwAIF3u8DRkbi1VOoeKGD pJ5C7ivfMc1kxGFKcpDRtvUpnpS8pOpVx03Af+iV/Dw+CHYxtsR0VlfkDeOU1/9OVouV Dkp2JHvtKhp8P/jAnq3zZviKAnF4GPGSJpottVrtwBGbJAV+gebKGT1uTCXSmy7O/ayz PgoEHsIvtkrF8ueCS0JG/qTcjBZPdt2rPArucfFHZ5UGNSjqQQwhj7OdZT7MuAP/80uL WMxA== X-Gm-Message-State: AOJu0YwAmwykYOQRAqNkUMiXBst3M07/yKYG5emLj3lTuqVJLGrVlb0Q +Ga2W1+RfY+vgCTZCIZMT/Cw3n5dsf09SpfHWftn0nTXPA/pnsKUC8p61DmCwcUPYqXncbHbU7i K7L13UuPtbqVvFuSbdQ7kQn1gdRxISOKu/IbKolAeFlm2vZnw0t0O5iIK96sT3pIzoRTZXR1G4Q == X-Received: by 2002:ac8:58c1:0:b0:423:9636:4876 with SMTP id u1-20020ac858c1000000b0042396364876mr481203qta.39.1701733292751; Mon, 04 Dec 2023 15:41:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlqYQoVkp9l+zpwV4B2+0DjBsrjDbvco5IeCnjG7DhfyQEnaaM0Nv+zlCO1WtMuRrclQxPAw== X-Received: by 2002:ac8:58c1:0:b0:423:9636:4876 with SMTP id u1-20020ac858c1000000b0042396364876mr481183qta.39.1701733292305; Mon, 04 Dec 2023 15:41:32 -0800 (PST) Received: from jason.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id o16-20020ac841d0000000b00423829b6d91sm4676766qtm.8.2023.12.04.15.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 15:41:31 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Cc: Jonathan Wakely Subject: [pushed] c++: fix constexpr noreturn diagnostic Date: Mon, 4 Dec 2023 18:41:29 -0500 Message-Id: <20231204234129.1445044-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.129.124; envelope-from=jason@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, 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+patchwork=sourceware.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- Mentioning a noreturn function does not involve an lvalue-rvalue conversion. gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1): Fix check for loading volatile lvalue. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-noreturn1.C: New test. --- gcc/cp/constexpr.cc | 3 ++- gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C base-commit: b6abc5dbfa5342347828b9feb4d9060071ff819c diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index b17e176aded..96c61666470 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -9387,7 +9387,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, available, so we don't bother with switch tracking. */ return true; - if (TREE_THIS_VOLATILE (t) && want_rval) + if (TREE_THIS_VOLATILE (t) && want_rval + && !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (t))) { if (flags & tf_error) constexpr_error (loc, fundef_p, "lvalue-to-rvalue conversion of " diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C new file mode 100644 index 00000000000..08c10e8dccb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-noreturn1.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++11 } } +// { dg-additional-options -Winvalid-constexpr } + +// We were giving a wrong error about loading a volatile value instead of the +// proper error about calling a non-constexpr function. + +[[noreturn]] void f(); + +constexpr int g() +{ + return f(), 42; // { dg-message "call to non-'constexpr' function" } +}