From: Jason Merrill Date: Fri, 22 Sep 2023 11:10:11 +0000 (+0100) Subject: c++: unroll pragma in templates [PR111529] X-Git-Tag: releases/gcc-11.5.0~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a644775c363979bc25951532819ffa0f244b82f4;p=thirdparty%2Fgcc.git c++: unroll pragma in templates [PR111529] 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.c (cp_parser_lambda_declarator_opt): Don't suggest -std=c++14 for lambda templates. * pt.c (tsubst_expr): Move ANNOTATE_EXPR handling... (tsubst_copy_and_build): ...here. gcc/testsuite/ChangeLog: * g++.dg/ext/unroll-4.C: New test. (cherry picked from commit 9c62af101e11e1cce573c2b3d2e18b403412dbc8) --- diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0619b834cf46..4f75f19ac50d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -11310,7 +11310,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) if (cxx_dialect < cxx14) pedwarn (parser->lexer->next_token->location, 0, "lambda templates are only available with " - "%<-std=c++14%> or %<-std=gnu++14%>"); + "%<-std=c++20%> or %<-std=gnu++20%>"); else if (cxx_dialect < cxx20) pedwarn (parser->lexer->next_token->location, OPT_Wpedantic, "lambda templates are only available with " diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 07515f63d299..8d39473de9e7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -19367,13 +19367,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, RECUR (TREE_OPERAND (t, 1)), 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))); @@ -21123,6 +21116,13 @@ tsubst_copy_and_build (tree t, with constant operands. */ RETURN (t); + 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)))); + case NON_LVALUE_EXPR: case VIEW_CONVERT_EXPR: if (location_wrapper_p (t)) 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 000000000000..1d1643a6bd99 --- /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 -w } + +template +void f() { + []() { + #pragma GCC unroll 9 + for (int i = 1; i; --i) { + } + }; +} + +int main() { + f<0>(); +}