]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: templates, attributes, #pragma target [PR114772]
authorJason Merrill <jason@redhat.com>
Wed, 16 Apr 2025 16:02:58 +0000 (12:02 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 23 Apr 2025 21:13:47 +0000 (17:13 -0400)
Since r12-5426 apply_late_template_attributes suppresses various global
state to avoid applying active pragmas to earlier declarations; we also
need to override target_option_current_node.

PR c++/114772
PR c++/101180

gcc/cp/ChangeLog:

* pt.cc (apply_late_template_attributes): Also override
target_option_current_node.

gcc/testsuite/ChangeLog:

* g++.dg/ext/pragma-target2.C: New test.

(cherry picked from commit 5fdb0145fb9499f5db9e27f775895ce4a39215e4)

gcc/cp/pt.cc
gcc/testsuite/g++.dg/ext/pragma-target2.C [new file with mode: 0644]

index d6cdab5ad80af00f6473d43920255c7ecfa08149..60ae00ce0dcda7ab38222d92c253cef443a46c35 100644 (file)
@@ -11907,6 +11907,8 @@ apply_late_template_attributes (tree *decl_p, tree attributes, int attr_flags,
   auto o3 = make_temp_override (current_target_pragma, NULL_TREE);
   auto o4 = make_temp_override (scope_chain->omp_declare_target_attribute,
                                NULL);
+  auto o6 = make_temp_override (target_option_current_node,
+                               target_option_default_node);
 
   cplus_decl_attributes (decl_p, late_attrs, attr_flags);
 
diff --git a/gcc/testsuite/g++.dg/ext/pragma-target2.C b/gcc/testsuite/g++.dg/ext/pragma-target2.C
new file mode 100644 (file)
index 0000000..53eb7dd
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/114772
+// { dg-do compile { target x86_64-*-* } }
+
+template<typename V, bool STREAMING>
+inline __attribute__((always_inline))
+__attribute__((warn_unused_result))
+int walk_document(V visitor) {return 0;}
+
+template<bool STREAMING>
+void parse_document() {
+    int r = walk_document<bool, STREAMING>(false);
+}
+
+void stage2_next() {
+    parse_document<true>();
+}
+
+#pragma GCC target("pclmul")