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.
{
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)
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;
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);