From patchwork Fri Sep 22 13:00:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1838252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OKIyYsev; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RsXT76Bmgz1yh6 for ; Fri, 22 Sep 2023 23:01:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 294B7385703F for ; Fri, 22 Sep 2023 13:01:11 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 82CB53858D39 for ; Fri, 22 Sep 2023 13:00:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82CB53858D39 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=1695387657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uLhAIM633ueUIeGQ8DbyVR//hNS9dvus6pZobS27KN4=; b=OKIyYsev8JOWeWgn1es8tZUf9vqxrMGeNY/QKR/ITEtGTofBIWlcfCrYeIZdu3g3WtQdPA 1nT9GNdtzLJpSBBKt5rSQG8WhW9vdBv5+oA3PSV4Gi9dCrIjrAJ1vhc2IXDOIUFiVGAI8I ++yoax0R9Favg6YayKN1P978Q9/jIEY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-265-MLHQRNNTN4W-G4gv3RNXEA-1; Fri, 22 Sep 2023 09:00:54 -0400 X-MC-Unique: MLHQRNNTN4W-G4gv3RNXEA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4030ae94fedso16399045e9.1 for ; Fri, 22 Sep 2023 06:00:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695387653; x=1695992453; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uLhAIM633ueUIeGQ8DbyVR//hNS9dvus6pZobS27KN4=; b=vNOhkCQL5eqVlGjxtnKAoT94ttBufaDPYUoyM0ME5WSOesABedOkipGShkCv8+f6lR qp/INP79fhBtJFNeVXXmwiU1F8joizTtFy/Wk+8asX89XpoPDh5BQHsmW8ob2rRPJRh7 VZimGAzd3xc0XIdhDumS/KaXs+4rJeVZAjaxApMsdZcFerMV59PgHQN3oIqGqnZt++KK 3fAuTNX2xwJ6GYQ8ltCrgX46AY1rU/2nixVLF158kNERdkO7ClVnOgV12j07ZbX3mWAu Mx8/wEy1CyM6nexJgE4cxe6yD5XT52T0qoivgvYFSL8dcp00ZHEOZWdQ9/dOOoxzQsmK 7+9A== X-Gm-Message-State: AOJu0YxnfJYoWRceKw/343U2WqXJ11dsWOh+xd8DBnv0k9WPYyQZEBhx 73hidHESc+wsBEXWsJndJUv+teV5UNlMWWWJBFRfmA7jPGa1nZZpxfQke06pcL5eD2FQNorbS/9 QYfq9kVbz63rMbycxgSH43wvAk+ul3hL3r6pV7iiZEo8qwwp6NGvyop7qZ6ajEPkaHRNQtdojNP Ev X-Received: by 2002:a05:600c:378c:b0:401:dc7c:2494 with SMTP id o12-20020a05600c378c00b00401dc7c2494mr8035816wmr.27.1695387652607; Fri, 22 Sep 2023 06:00:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHU+TNhGEutvyrb7C+haFXrYHvyhAk6D+MnE6VnbVITXOZQIxzKoyVBLWpkrjKl0AmrVn5O4w== X-Received: by 2002:a05:600c:378c:b0:401:dc7c:2494 with SMTP id o12-20020a05600c378c00b00401dc7c2494mr8035731wmr.27.1695387651043; Fri, 22 Sep 2023 06:00:51 -0700 (PDT) Received: from jason.com ([195.89.33.213]) by smtp.gmail.com with ESMTPSA id s2-20020a5d5102000000b0031f82743e25sm4386871wrt.67.2023.09.22.06.00.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 06:00:50 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: unroll pragma in templates [PR111529] Date: Fri, 22 Sep 2023 14:00:47 +0100 Message-Id: <20230922130047.258143-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 X-Spam-Status: No, score=-12.0 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_H4, RCVD_IN_MSPIKE_WL, 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 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- We were failing to handle ANNOTATE_EXPR in tsubst_copy_and_build, leading to problems with substitution of any wrapped expressions. Let's also not tell users that lambda templates are available in C++14. PR c++/111529 gcc/cp/ChangeLog: * parser.cc (cp_parser_lambda_declarator_opt): Don't suggest -std=c++14 for lambda templates. * pt.cc (tsubst_expr): Move ANNOTATE_EXPR handling... (tsubst_copy_and_build): ...here. gcc/testsuite/ChangeLog: * g++.dg/ext/unroll-4.C: New test. --- gcc/cp/parser.cc | 7 ++----- gcc/cp/pt.cc | 14 +++++++------- gcc/testsuite/g++.dg/ext/unroll-4.C | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/unroll-4.C base-commit: 4c496020764057453415f1ae599950724ec0e871 diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 0e1cbbfe051..f3abae716fe 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -11695,11 +11695,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) an opening angle if present. */ if (cp_lexer_next_token_is (parser->lexer, CPP_LESS)) { - if (cxx_dialect < cxx14) - pedwarn (parser->lexer->next_token->location, OPT_Wc__14_extensions, - "lambda templates are only available with " - "%<-std=c++14%> or %<-std=gnu++14%>"); - else if (pedantic && cxx_dialect < cxx20) + if (cxx_dialect < cxx20 + && (pedantic || cxx_dialect < cxx14)) pedwarn (parser->lexer->next_token->location, OPT_Wc__20_extensions, "lambda templates are only available with " "%<-std=c++20%> or %<-std=gnu++20%>"); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 9b100e12a23..ea5379098a5 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -19913,13 +19913,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) templated_operator_saved_lookups (t), complain)); - case ANNOTATE_EXPR: - tmp = RECUR (TREE_OPERAND (t, 0)); - RETURN (build3_loc (EXPR_LOCATION (t), ANNOTATE_EXPR, - TREE_TYPE (tmp), tmp, - RECUR (TREE_OPERAND (t, 1)), - RECUR (TREE_OPERAND (t, 2)))); - case PREDICT_EXPR: RETURN (add_stmt (copy_node (t))); @@ -21868,6 +21861,13 @@ tsubst_copy_and_build (tree t, RETURN (op); } + case ANNOTATE_EXPR: + op1 = RECUR (TREE_OPERAND (t, 0)); + RETURN (build3_loc (EXPR_LOCATION (t), ANNOTATE_EXPR, + TREE_TYPE (op1), op1, + RECUR (TREE_OPERAND (t, 1)), + RECUR (TREE_OPERAND (t, 2)))); + default: /* Handle Objective-C++ constructs, if appropriate. */ { diff --git a/gcc/testsuite/g++.dg/ext/unroll-4.C b/gcc/testsuite/g++.dg/ext/unroll-4.C new file mode 100644 index 00000000000..d488aca974e --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/unroll-4.C @@ -0,0 +1,16 @@ +// PR c++/111529 +// { dg-do compile { target c++11 } } +// { dg-additional-options -Wno-c++20-extensions } + +template +void f() { + []() { + #pragma GCC unroll 9 + for (int i = 1; i; --i) { + } + }; +} + +int main() { + f<0>(); +}