[cfe-dev] Attributes on templates/namespaces

Don Williamson don.williamson at yahoo.com
Thu Jan 26 06:31:33 PST 2012


Hi,

Does clang support attributes on templates? My understanding is their design is based on GCC attributes and the GCC documentation doesn't specify template support:

http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html

This also excludes support for namespace attributes. When I try to use attributes on namespaces, I get the following:

__attribute__((annotate("attr"))) namespace core {
error: expected unqualified-id


namespace __attribute__((annotate("attr"))) core {
error: expected identifier or '{'

namespace core __attribute__((annotate("attr"))) {
Compiles fine!

However, when I inspect the attributes using clang::Decl::attr_begin, there are no attributes there.

I'm having the same issue with templates:

__attribute__((annotate("attr"))) template <typename T> struct Vector {

error: expected unqualified-id

template <typename T> __attribute__((annotate("attr"))) struct Vector {
Compiles fine!

template <typename T> struct __attribute__((annotate("attr"))) Vector {
Compiles fine!

template <typename T> struct Vector __attribute__((annotate("attr"))) {
:  error: expected unqualified-id

In all the cases where it compiles fine for the template case above, there are no attributes in the AST.

Am I using the wrong means of getting the attribute list? It works for classes, fields, functions and enumerations so far.

Thanks,
- Don
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120126/0452309e/attachment.html>


More information about the cfe-dev mailing list