Skip to content

.template not followed by template arguments is incorrectly accepted #53095

Closed
@HolyBlackCat

Description

@HolyBlackCat

Consider this example:

#include <iostream>

struct A
{
    void foo() {std::cout << "1\n";}
    
    template <typename T = int>
    void foo() {std::cout << "2\n";}
};

int main()
{
    A x;
    x.template foo();
}

Clang prints 2. But the code shouldn't be accepted at all, since [temp.names]/5 says that the name after .template/->template must be a template-id, aka must have explicitly specified template arguments. Here's a stackoverflow thread.

Note: this doesn't apply to foo::template MyClassTemplate, which is legal, but seems to be made optional (and deprecated at the same time) in C++2b.

Metadata

Metadata

Assignees

Labels

accepts-invalidc++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"good first issuehttps://github.com/llvm/llvm-project/contribute

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions