Constructor
Constructor

Reputation: 7483

Pseudo-destructor call with template keyword

The following code does not compile with clang 5.0.0 (compilation flags are -std=c++14 -Wall -Wextra -Werror -pedantic-errors -O0):

struct foo
{
};

int main()
{
    foo f;

    f.~decltype(f)();          // OK
    f.template ~decltype(f)(); // OK

    int i{};

    i.~decltype(i)();          // OK
    i.template ~decltype(i)(); // error: expected unqualified-id
}

Is it a way to force the compilation of a pseudo-destructor call with the template keyword?

Upvotes: 3

Views: 167

Answers (1)

Qaz
Qaz

Reputation: 61970

As far as I can tell, [temp.names]/5 prohibits both of these .template … lookups:

A name prefixed by the keyword template shall be a template-id or the name shall refer to a class template or an alias template. [ Note: The keyword template may not be applied to non-template members of class templates. — end note ]

None of these destructor names are template-ids, nor do they refer to class templates or alias templates. However, it's possible that I'm missing something.

Upvotes: 4

Related Questions