aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-03-06 17:58:14 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2025-03-06 17:58:14 +0100
commit0ba3e5ff14a48f1fb7ca53cb86194e08d5b5da66 (patch)
tree0126ad4ae20502a1a31ec6520a0dbbc4b1348693 /gcc
parent1ccbf8e2c2496779862a0153ed95459f72794521 (diff)
downloadgcc-0ba3e5ff14a48f1fb7ca53cb86194e08d5b5da66.zip
gcc-0ba3e5ff14a48f1fb7ca53cb86194e08d5b5da66.tar.gz
gcc-0ba3e5ff14a48f1fb7ca53cb86194e08d5b5da66.tar.bz2
c++: Fix up instantiation of pointer/reference/array types with attributes [PR119138]
My r15-7822 PR118787 change unfortunately broke build on x86_64-w64-mingw32. The reduced testcase below shows what is going on. va_list on this target is char * with extra (non-dependent) attributes on it. Before my r15-7822 change, instantiation of such type used the fast path and just returned t, but as it has non-NULL TYPE_ATTRIBUTES, it now falls through, builds a pointer type and then calls apply_late_template_attributes. And in there triggers a bug, that function has been written for types with RECORD_TYPE/UNION_TYPE (or ENUMERAL_TYPE?) in mind, where we call apply_late_template_attributes with ATTR_FLAG_TYPE_IN_PLACE and can just apply the non-dependent attributes directly to TYPE_ATTRIBUTES. That is wrong for shared types like {POINTER,REFERENCE,ARRAY}_TYPE etc., we should just force cp_build_type_attribute_variant to build a variant type for the non-dependent attributes and then process dependent attributes (which given attr_flag will DTRT already). The second change in the patch is an optimization, we can actually return back to returning t even when TYPE_ATTRIBUTES is non-NULL, as long as it is non-dependent (dependent attributes are stored first, so it is enough to check the first attribute). 2025-03-06 Jakub Jelinek <jakub@redhat.com> PR c++/119138 * pt.cc (apply_late_template_attributes): Set p to NULL if ATTR_FLAG_TYPE_IN_PLACE is not set in attr_flags. (tsubst) <case POINTER_TYPE, case REFERENCE_TYPE, case ARRAY_TYPE>: Reuse original type even if TYPE_ATTRIBUTES is non-NULL, but all the attributes are non-dependent. * g++.dg/template/pr119138.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.cc9
-rw-r--r--gcc/testsuite/g++.dg/template/pr119138.C16
2 files changed, 22 insertions, 3 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c09a934..2775af7 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -12393,7 +12393,8 @@ apply_late_template_attributes (tree *decl_p, tree attributes, int attr_flags,
to our attributes parameter. */
gcc_assert (*p == attributes);
}
- else if (FUNC_OR_METHOD_TYPE_P (*decl_p))
+ else if (FUNC_OR_METHOD_TYPE_P (*decl_p)
+ || (attr_flags & ATTR_FLAG_TYPE_IN_PLACE) == 0)
p = NULL;
else
{
@@ -16867,7 +16868,8 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
{
if (type == TREE_TYPE (t)
&& TREE_CODE (type) != METHOD_TYPE
- && TYPE_ATTRIBUTES (t) == NULL_TREE)
+ && (TYPE_ATTRIBUTES (t) == NULL_TREE
+ || !ATTR_IS_DEPENDENT (TYPE_ATTRIBUTES (t))))
return t;
/* [temp.deduct]
@@ -17029,7 +17031,8 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
it will obviously be the same as T. */
if (type == TREE_TYPE (t)
&& domain == TYPE_DOMAIN (t)
- && TYPE_ATTRIBUTES (t) == NULL_TREE)
+ && (TYPE_ATTRIBUTES (t) == NULL_TREE
+ || !ATTR_IS_DEPENDENT (TYPE_ATTRIBUTES (t))))
return t;
/* These checks should match the ones in create_array_type_for_decl.
diff --git a/gcc/testsuite/g++.dg/template/pr119138.C b/gcc/testsuite/g++.dg/template/pr119138.C
new file mode 100644
index 0000000..b089387
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr119138.C
@@ -0,0 +1,16 @@
+// PR c++/119138
+// { dg-do compile }
+
+#include <stdarg.h>
+
+template <typename>
+void
+foo (va_list)
+{
+}
+
+void
+bar (va_list ap)
+{
+ foo <char> (ap);
+}