[gcc r16-5937] c++: is_late_template_attribute and tsubst_attribute fixes
Jakub Jelinek
jakub@gcc.gnu.org
Sat Dec 6 10:08:41 GMT 2025
https://gcc.gnu.org/g:3b7e865779d03b4d29375a3c28dfaa2172eced4a
commit r16-5937-g3b7e865779d03b4d29375a3c28dfaa2172eced4a
Author: Jakub Jelinek <jakub@redhat.com>
Date: Sat Dec 6 11:07:18 2025 +0100
c++: is_late_template_attribute and tsubst_attribute fixes
This has been discussed in the 1/9 Reflection thread, but doesn't depend on
reglection in any way.
cp_parser_std_attribute calls lookup_attribute_spec as:
const attribute_spec *as
= lookup_attribute_spec (TREE_PURPOSE (attribute));
so with TREE_LIST where TREE_VALUE is attribute name and TREE_PURPOSE
attribute ns. Similarly c_parser_std_attribute. And for
attribute_takes_identifier_p those do:
else if (attr_ns == gnu_identifier
&& attribute_takes_identifier_p (attr_id))
and
bool takes_identifier
= (ns != NULL_TREE
&& strcmp (IDENTIFIER_POINTER (ns), "gnu") == 0
&& attribute_takes_identifier_p (name));
when handling std attributes (for GNU attributes they just call those
with the IDENTIFIER_NODE name.
is_late_template_attribute and tsubst_attribute pass to these functions
just get_attribute_name though, so handle attributes in all namespaces
as GNU attributes only, which means that lookup_attribute_spec can
return NULL or find a different attribute if it is not from gnu:: or
say standard attribute mapped to gnu::, or attribute_takes_identifier_p
can return true even for attributes for which it shouldn't.
I thought about changing attribute_takes_identifier_p to take optionally
TREE_LIST, but that would mean handling it in the target hooks too and
they only care about GNU attributes right now, so given the above
parser.cc/c-parser.cc snippets, the following patch just follow
what they do.
2025-12-06 Jakub Jelinek <jakub@redhat.com>
* decl2.cc (is_late_template_attribute): Call lookup_attribute_spec
on TREE_PURPOSE (attr) rather than name. Only call
attribute_takes_identifier_p if get_attribute_namespace (attr) is
gnu_identifier.
* pt.cc (tsubst_attribute): Only call attribute_takes_identifier_p
if get_attribute_namespace (t) is gnu_identifier.
Diff:
---
gcc/cp/decl2.cc | 7 +++++--
gcc/cp/pt.cc | 3 ++-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index 9e135af41b34..8ec9740c8a9e 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -1468,7 +1468,8 @@ is_late_template_attribute (tree attr, tree decl)
{
tree name = get_attribute_name (attr);
tree args = TREE_VALUE (attr);
- const struct attribute_spec *spec = lookup_attribute_spec (name);
+ const struct attribute_spec *spec
+ = lookup_attribute_spec (TREE_PURPOSE (attr));
tree arg;
if (!spec)
@@ -1512,7 +1513,9 @@ is_late_template_attribute (tree attr, tree decl)
second and following arguments. Attributes like mode, format,
cleanup and several target specific attributes aren't late
just because they have an IDENTIFIER_NODE as first argument. */
- if (arg == args && attribute_takes_identifier_p (name)
+ if (arg == args
+ && get_attribute_namespace (attr) == gnu_identifier
+ && attribute_takes_identifier_p (name)
&& identifier_p (t))
continue;
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 7a019d33bda1..8498730b6e43 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -12386,7 +12386,8 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
pass it through tsubst. Attributes like mode, format,
cleanup and several target specific attributes expect it
unmodified. */
- else if (attribute_takes_identifier_p (get_attribute_name (t)))
+ else if (get_attribute_namespace (t) == gnu_identifier
+ && attribute_takes_identifier_p (get_attribute_name (t)))
{
tree chain
= tsubst_expr (TREE_CHAIN (val), args, complain, in_decl);
More information about the Gcc-cvs
mailing list