https://gcc.gnu.org/g:a644775c363979bc25951532819ffa0f244b82f4

commit r11-11448-ga644775c363979bc25951532819ffa0f244b82f4
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri Sep 22 12:10:11 2023 +0100

    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:
---
 gcc/cp/parser.c                     |  2 +-
 gcc/cp/pt.c                         | 14 +++++++-------
 gcc/testsuite/g++.dg/ext/unroll-4.C | 16 ++++++++++++++++
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 0619b834cf4..4f75f19ac50 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 07515f63d29..8d39473de9e 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 00000000000..1d1643a6bd9
--- /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 <int>
+void f() {
+  []<int>() {
+    #pragma GCC unroll 9
+    for (int i = 1; i; --i) {
+    }
+  };
+}
+
+int main() {
+  f<0>();
+}

Reply via email to