11

In C++ reference I found information about allowed syntax of attributes in C++, it is:

[[attribute-list]]
[[ using attribute-namespace : attribute-list ]]

"where attribute-list is a comma-separated sequence of zero or more attributes (possibly ending with an ellipsis ... indicating a pack expansion)"

I've tried to use its, but I see no difference between:

[[deprecated]] void f() 
{
}

and

[[deprecated...]] void f() 
{
}

In both cases output is the same.

baziorek
  • 2,502
  • 2
  • 29
  • 43
  • 7
    *(possibly ending with an ellipsis ... indicating a pack expansion)* is what the reference says. When you could use it? No idea, it's an underdeveloped feature imho... Perhaps the grammar allows it for future expansions. – DeiDei Feb 26 '18 at 00:09
  • 2
    I believe [this paper](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2843.html) may be relevant. – Arnav Borborah Feb 26 '18 at 00:11
  • I wonder why does `[[deprecated...]]` even compile if there are no packs to expand. – HolyBlackCat Feb 26 '18 at 00:29
  • 1
    You may find [this video](https://youtu.be/Pt6oeIpzue4) to be relevant – Justin Feb 26 '18 at 01:14

1 Answers1

2

This was added to the specification for consistency and also because the future of attributes is still being discussed. Considering that we currently have pack expansion in variadic templates (see Variadic template pack expansion) like this:

// pack expansion in function arguments
template <typename... Args>
void f(Args... args) {}

// pack expansion in inheritance
template <typename... Inherited>
struct MyClass : Inherited... {};

Along the same lines, it also makes sense to think about pack expansion for attributes. A few example scenarios could be:

template <typename... Ts>
class [[Ts...]] MyClass {};

or

template <typename... Ts>
class [[Ts()...]] MyClass {};

But, again, this is only in the specification and currently there is no attribute that can be used like that.

HugoTeixeira
  • 4,674
  • 3
  • 22
  • 32
  • Both examples of how they could be used fail to compile on GCC and clang even without instantiation. Is this expected? – qz- Sep 24 '21 at 17:56
  • But... how is a type an attribute? https://godbolt.org/z/TMz56hesb – Ben Jul 27 '22 at 23:57