xmh0511
xmh0511

Reputation: 7369

How to understand "abstract-declarator containing an ellipsis shall only be used in a parameter-declaration"

Consider the following quote,It says:
[dcl.fct]/16

A declarator-id or abstract-declarator containing an ellipsis shall only be used in a parameter-declaration.[...]

I agree with A declarator-id containing an ellipsis shall only be used in a parameter-declaration,Because we can't use something like ...id-expression in anywhere,it can only appear in parameter-declaration,so it's 100% clear.However,about abstract-declarator containing an ellipsis shall only be used in a parameter-declaration,please consider the below code:

#include <iostream>
#include <tuple>
template<typename...T>
void func(T...){
  std::tuple<T...> tup;  //#1
}

[dcl.name]

type-id:

type-specifier-seq abstract-declarator(opt)

How about #1,it's not parameter-declaration,howerver,the abstract-declarator that contain an ellipsis is used within type-id in that context.So,Is my understanding about abstract-declarator wrong?

Upvotes: 4

Views: 134

Answers (1)

Mark
Mark

Reputation: 1056

The ellipsis is not part of a type-id, but of a template-argument-list.

If we apply the following grammar from [temp.names]

simple-template-id:
    template-name < template-argument-listopt >

template-name:
    identifier

template-argument-list:
    template-argument ...opt
    [...]

template-argument:
    type-id
    [...]

to your example, we get:

   std::tuple<T...> tup;
//      tuple<T...>       simple-template-id
//      tuple             template-name
//            T...        template-argument-list
//            T           template-argument, type-id

Then, [temp.arg]/9

A template-argument followed by an ellipsis is a pack expansion.

applies, which is what we'd expect.

Upvotes: 5

Related Questions