From patchwork Tue Feb 8 08:16:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 50906 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 383673858426 for ; Tue, 8 Feb 2022 08:17:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 383673858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644308227; bh=ZuvBGcXaBYJn7zWcUb1TYJL49VOd1Ppq+76jeSeY6BI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=fFQ6xJxCgJYNaG6TftP11qH1O0oFHpTeixdUHA0htrXVAnn0aQGN/rBdInPOKcGpi EQCoONAQhDun1SyN6NV15hRveGaqDIicn9yTwPIXKk9+BZfAeGTymhaV7T7JZeuWUW rHRCotUg/bUt0OEdJ0c1cgHGmkRyktHPd+L+dI4E= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 29005385841A for ; Tue, 8 Feb 2022 08:16:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 29005385841A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-551-P7hwk3HPNq6NPyEfrFTAzg-1; Tue, 08 Feb 2022 03:16:18 -0500 X-MC-Unique: P7hwk3HPNq6NPyEfrFTAzg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A131614755 for ; Tue, 8 Feb 2022 08:16:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F34F6C1B1; Tue, 8 Feb 2022 08:16:17 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 2188GEcU3380453 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 8 Feb 2022 09:16:15 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 2188GEWE3380452; Tue, 8 Feb 2022 09:16:14 +0100 Date: Tue, 8 Feb 2022 09:16:14 +0100 To: Jason Merrill Subject: [PATCH] c++: Remove superflous assert [PR104403] Message-ID: <20220208081614.GC2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! I've added the assert because start_decl diagnoses such vars for C++20 and earlier: if (current_function_decl && VAR_P (decl) && DECL_DECLARED_CONSTEXPR_P (current_function_decl) && cxx_dialect < cxx23) but as can be seen, we cam trigger the assert in older standards e.g. during non-manifestly constant evaluation. Rather than refining the assert that DECL_EXPRs for such vars don't appear for C++20 and older if they are inside of functions declared constexpr this patch just removes the assert, the code rejects encountering those vars in constant expressions anyway. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-02-08 Jakub Jelinek PR c++/104403 * constexpr.cc (cxx_eval_constant_expression): Don't assert DECL_EXPRs of TREE_STATIC vars may only appear in -std=c++23. * g++.dg/cpp0x/lambda/lambda-104403.C: New test. Jakub --- gcc/cp/constexpr.cc.jj 2022-02-06 11:16:22.353814431 +0100 +++ gcc/cp/constexpr.cc 2022-02-07 11:38:59.131165171 +0100 @@ -6652,7 +6652,6 @@ cxx_eval_constant_expression (const cons /* Allow __FUNCTION__ etc. */ && !DECL_ARTIFICIAL (r)) { - gcc_assert (cxx_dialect >= cxx23); if (!ctx->quiet) { if (CP_DECL_THREAD_LOCAL_P (r)) --- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-104403.C.jj 2022-02-07 11:40:32.760847269 +0100 +++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-104403.C 2022-02-07 11:40:06.109223079 +0100 @@ -0,0 +1,8 @@ +// PR c++/104403 +// { dg-do compile { target c++11 } } + +int +main () +{ + []{ switch (0) { case 0: static int value; return &value; } }; +}