]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: unroll pragma in templates [PR111529]
authorJason Merrill <jason@redhat.com>
Fri, 22 Sep 2023 11:10:11 +0000 (12:10 +0100)
committerJason Merrill <jason@redhat.com>
Fri, 24 May 2024 18:38:01 +0000 (14:38 -0400)
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)

gcc/cp/parser.c
gcc/cp/pt.c
gcc/testsuite/g++.dg/ext/unroll-4.C [new file with mode: 0644]

index 0619b834cf46880a8bb9c426d0e934e5a392e0a4..4f75f19ac50d5d7647947247459c118a269ae309 100644 (file)
@@ -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 "
index 07515f63d299019560b1ae6e3bb8a7c97bb75a12..8d39473de9e7e4f8191a1634ced3457807f24973 100644 (file)
@@ -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 (file)
index 0000000..1d1643a
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/111529
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -w }
+
+template <int>
+void f() {
+  []<int>() {
+    #pragma GCC unroll 9
+    for (int i = 1; i; --i) {
+    }
+  };
+}
+
+int main() {
+  f<0>();
+}