From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 614DB385828E for ; Fri, 17 Feb 2023 22:45:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 614DB385828E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676673944; 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: in-reply-to:in-reply-to:references:references; bh=v0n7uh03LXMqfMwnGAwfTIJoHyGoe85lj3HFoe3wopE=; b=FJDPZGM5NvqNTlBpj3PF0uHWEGSmjaKd2yc0IK3rFJ9Sb/EuLYNEHp32fMhHVoVCVCRQH9 h1UnSu7LhPCe3gc0Eiwb0YgmHDsdXwOCq5fphmix6LweRyfYdbdt5WYZFUhvZu9ZCws21U kpdrhp8SHkmw77dBPWY/V6rCWzPG9oI= 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_128_GCM_SHA256) id us-mta-381-SGYMS_fhOVuH2HhMeSKyWA-1; Fri, 17 Feb 2023 17:45:43 -0500 X-MC-Unique: SGYMS_fhOVuH2HhMeSKyWA-1 Received: by mail-qt1-f197.google.com with SMTP id j16-20020ac874d0000000b003b9bd2a2284so1442103qtr.4 for ; Fri, 17 Feb 2023 14:45:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v0n7uh03LXMqfMwnGAwfTIJoHyGoe85lj3HFoe3wopE=; b=b8KfnT+HrIVf/S0UPTQHV5h3t2fkjjqK5XQY+8/SaPC9CNmpmnVMjYBJtqSM6OdyCC iT4gd6lDEt2b/Hc/waSjenkMCMhofix79Efi0MRnjxDIjl98CcA8IOFtiScwblgqPR1o QfPZSyvPb59IDnTOUkqsqPnKZLYNW7+kZBNxa94nHCu0HcKdOB/9pqKLUxIEb6YMaCLd gHwpyP3agJ39euq4h+YWmzvB23V6O08XcIAqR4EdI/gUGtEpUmSTLAw6sLVM2lHHbAlC 99hIGVY7Kchuyxgj9EpMSdVCBX5FJLArqSksXC3BUzQOSG95Hc5wMCySdHNZ019zJvPM savw== X-Gm-Message-State: AO0yUKWjMNuCb2FzUTST2hgSHqCwb5PbUDIvbvS504TbcjH7jvBbZVlu UBFsxV8ygn+9BaJWjjekqIshP6sgf/iB+kecgGBF3AYySbcb5l9QyjzwO/+h33lmNS3nFymhVLG MFPHmBKuKuyJJbQX/Zg== X-Received: by 2002:ac8:5d8d:0:b0:3b6:36a0:adbe with SMTP id d13-20020ac85d8d000000b003b636a0adbemr3604003qtx.6.1676673942507; Fri, 17 Feb 2023 14:45:42 -0800 (PST) X-Google-Smtp-Source: AK7set+/PeoI4ShoVu+JmUjmIw5J3jRoVumL9lFhC6D1c90ADyogX2wVWn43HU8qw71Ki/8YfI0+dw== X-Received: by 2002:ac8:5d8d:0:b0:3b6:36a0:adbe with SMTP id d13-20020ac85d8d000000b003b636a0adbemr3603974qtx.6.1676673942162; Fri, 17 Feb 2023 14:45:42 -0800 (PST) Received: from redhat.com (2603-7000-9500-34a5-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:34a5::1db4]) by smtp.gmail.com with ESMTPSA id e26-20020ac8415a000000b003b635a5d56csm4069200qtm.30.2023.02.17.14.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 14:45:41 -0800 (PST) Date: Fri, 17 Feb 2023 17:45:39 -0500 From: Marek Polacek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH RFC] c++: static_assert (false) in template [DR2518] Message-ID: References: <20230217203209.2141339-1-jason@redhat.com> MIME-Version: 1.0 In-Reply-To: <20230217203209.2141339-1-jason@redhat.com> User-Agent: Mutt/2.2.9 (2022-11-12) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-12.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_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Feb 17, 2023 at 03:32:09PM -0500, Jason Merrill via Gcc-patches wrote: > Tested x86_64-pc-linux-gnu. This isn't really a regression fix, but it's very > safe, and fixes a longstanding annoyance, so I'm leaning toward putting it into > GCC 13. Thoughts? LGTM. > -- 8< -- > > For a long time, people have expected to be able to write > static_assert (false) in a template and only have it diagnosed if the > template is instantiated, but we (and other implementations) gave an error > about the uninstantiated template because the standard says that if no valid > instantiation of the template is possible, the program is ill-formed, no > diagnostic required, and we try to diagnose IFNDR things when feasible. > > At the meeting last week we were looking at CWG2518, which wanted to specify > that an implementation must not accept a program containing a failing #error > or static_assert. We also looked at P2593, which proposed allowing > static_assert in an uninstantiated template. We ended up combining these > two in order to avoid requiring implementations to reject programs with > static_assert (false) in uninstantiated templates. > > The committee accepted this as a DR, so I'm making the change to all > standard modes. This behavior was also conformant previously, since no > diagnostic was required in this case. > > We continue to diagnose non-constant or otherwise ill-formed conditions, so > no changes to existing tests were needed. > > DR 2518 > PR c++/52809 > PR c++/53638 > PR c++/87389 > PR c++/89741 > PR c++/92099 > PR c++/104041 > PR c++/104691 > > gcc/cp/ChangeLog: > > * semantics.cc (finish_static_assert): Don't diagnose in > template context. > > gcc/testsuite/ChangeLog: > > * g++.dg/DRs/dr2518.C: New test. > --- > gcc/cp/semantics.cc | 17 ++++++++++------- > gcc/testsuite/g++.dg/DRs/dr2518.C | 7 +++++++ > 2 files changed, 17 insertions(+), 7 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/DRs/dr2518.C > > diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc > index c2df0b69b30..79b7cc72f21 100644 > --- a/gcc/cp/semantics.cc > +++ b/gcc/cp/semantics.cc > @@ -11232,14 +11232,16 @@ finish_static_assert (tree condition, tree message, location_t location, > if (check_for_bare_parameter_packs (condition)) > condition = error_mark_node; > > + /* Save the condition in case it was a concept check. */ > + tree orig_condition = condition; > + > if (instantiation_dependent_expression_p (condition)) > { > /* We're in a template; build a STATIC_ASSERT and put it in > the right place. */ > - tree assertion; > - > - assertion = make_node (STATIC_ASSERT); > - STATIC_ASSERT_CONDITION (assertion) = condition; > + defer: > + tree assertion = make_node (STATIC_ASSERT); > + STATIC_ASSERT_CONDITION (assertion) = orig_condition; > STATIC_ASSERT_MESSAGE (assertion) = message; > STATIC_ASSERT_SOURCE_LOCATION (assertion) = location; > > @@ -11253,9 +11255,6 @@ finish_static_assert (tree condition, tree message, location_t location, > return; > } > > - /* Save the condition in case it was a concept check. */ > - tree orig_condition = condition; > - > /* Fold the expression and convert it to a boolean value. */ > condition = contextual_conv_bool (condition, complain); > condition = fold_non_dependent_expr (condition, complain, > @@ -11270,6 +11269,10 @@ finish_static_assert (tree condition, tree message, location_t location, > > if (integer_zerop (condition)) > { > + /* CWG2518: static_assert failure in a template is not IFNDR. */ > + if (processing_template_decl) > + goto defer; > + > int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT > (TREE_TYPE (TREE_TYPE (message)))); > int len = TREE_STRING_LENGTH (message) / sz - 1; > diff --git a/gcc/testsuite/g++.dg/DRs/dr2518.C b/gcc/testsuite/g++.dg/DRs/dr2518.C > new file mode 100644 > index 00000000000..240186211e6 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/DRs/dr2518.C > @@ -0,0 +1,7 @@ > +// CWG 2518 > +// { dg-do compile { target c++11 } } > + > +template void f() > +{ > + static_assert (false, ""); > +} > > base-commit: 07f497c2da3600cc99cd7d1b5c6726972fb2b5a1 > -- > 2.31.1 > Marek