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: 143419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5552044vqi; Fri, 22 Sep 2023 06:01:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5byqTCV52wnY/AkeEe4aLyYv95S3/jY1M8pA995U7AzOwVXnitt1erhtVSyzxFdko0TbT X-Received: by 2002:a17:906:20d4:b0:9a1:f928:dddc with SMTP id c20-20020a17090620d400b009a1f928dddcmr7600041ejc.41.1695387719045; Fri, 22 Sep 2023 06:01:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695387719; cv=none; d=google.com; s=arc-20160816; b=gdQDuKY6KGxCc3mAyK66nwVEqJoRFz0TwMyOF2FFd3aq7qIhbI8JKKe2iXIFkaDHR/ szm1wX4ZVn1Cx7yMsCOuyXjHh5s7zVT0AiVS419/Yn5vFvWIHHQ2TWlqiKyKOmr5W3qK +X1p4YCGk8yckS5HsKAQjgcxn2Nfs3nl1ZnwFwiPPsjN58zK/ie6EG9NQKMKKHco2XI7 REBukSMuhDyPyEdY4HbkmQCHjx/1MDm/QiQMORkhAanHs9HiP1E2Pn3naTI6F2evWsV1 KVlvcl9E8ojKQy+98gh2lc9/75CM2vfp3WlnrzlSsTwJnKdIolIlEoxFQxf3FS8+GNfl luxQ== ARC-Message-Signature: i=1; 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:to:from:dkim-signature :dmarc-filter:delivered-to; bh=uLhAIM633ueUIeGQ8DbyVR//hNS9dvus6pZobS27KN4=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=PxC0llurF2kBx0u4HD08FQgraeIHFONbU2+fg/daV81LXP9wJirRBGIt6+E9JP6La1 rGPna95NvvxAxZz4WkERDr/+6e3ZePO7clBo+03yQnCdzbA3rReSH63x05PcV6KOo8U/ Ji8DzcF+1dzzI+7oSosKAC5JK4tNGKPJ2hSPe+kVK59csCwEML1jw5o561BV6vKxX6db yCq3hiWU6l84JrGC8BUxI5ts1E2AiQD8ktOJK7aD8qgEsJb/IO5IBAsurtWM8KqoTfmS guQwZNyEuSJc2WxC9LrKHSa/r6wfDJ+l5rNPO5d5tX9FjP534etC0gYwKPcueBu42YIf w7Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OKIyYsev; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qh2-20020a170906eca200b0099845f657a9si3304803ejb.662.2023.09.22.06.01.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 06:01:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OKIyYsev; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 3C70A385C6EF for ; Fri, 22 Sep 2023 13:01:24 +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-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777742872564671226 X-GMAIL-MSGID: 1777742872564671226 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>(); +}