On Wed, Jun 18, 2025 at 11:34:42AM +0200, Pierrick Philippe wrote:
> Hi everyone,
> 
> I am currently reading the C23 standard along the pre-release GCC 16
> documentations (users and internals), and I noticed that there is no
> mention on how to create new attributes using the new C23 standard
> attribute specifier ('[[new_attr]]').
> I mean, I believe it would be transparent from the attribute handling
> whether you specified it with the C23 standard notation or the
> traditional GNU syntax.
> But what I mean is that I could not find in the source code where the
> 'gnu::' namespace prefix is created, or if they were means to create new
> namespace prefix for attributes from external plugins.
> 
> So I do have two questions:
> 
> 1 - Is the current implementation fully compatible with the '[[]]'
> attribute specifier syntax?

Sure.

> 2 - Are there means to create new namespace prefix attribute from plugin
> code ?

See e.g.
...
const struct scoped_attribute_specs c_common_gnu_attribute_table =
{
  "gnu", { c_common_gnu_attributes }
};
...
const struct scoped_attribute_specs c_common_clang_attribute_table =
{
  "clang", { c_common_clang_attributes }
};
in c-family/c-attribs.cc.
E.g. c/c-objc-common.h then registers those:
static const scoped_attribute_specs *const c_objc_attribute_table[] =
{
  &std_attribute_table,
  &c_common_gnu_attribute_table,
  &c_common_clang_attribute_table,
  &c_common_format_attribute_table
};

#undef LANG_HOOKS_ATTRIBUTE_TABLE
#define LANG_HOOKS_ATTRIBUTE_TABLE c_objc_attribute_table
Backends or plugins can register further attributes (or further attributes
in specific namespaces).

If all you care is whether in source code you can use some different
attribute namespace, you can, just use [[whatever::something]] etc.,
perhaps with warnings from the compiler, or -Wno-attributes=whatever::
or -Wno-attributes=whatever::something options allows to ignore warnings
about specific attributes.

        Jakub

Reply via email to