llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Clang accepts invalid program involving template keyword when used without a template arg list

Open ranaanoop opened this issue 2 years ago • 5 comments

The following invalid program(as per [temp.name#6]) compiles with gcc and clang. Demo

template<typename T>
struct C
{
     template<typename U> void func(U)
     {

     }
};
int main()
{
    C<int> c;  
    c.template func(5); //this is invalid as per current wording gcc and clang accepts but msvc correctly rejects     
    //c.template func<>(5); //valid as per current wording. All compilers accepts this
}

ranaanoop avatar Jan 13 '24 12:01 ranaanoop

@llvm/issue-subscribers-clang-frontend

Author: Anoop Rana (ranaanoop)

The following invalid program(as per [temp.name#6]) compiles with gcc and clang. [Demo](https://godbolt.org/z/Yrj94haa4)
template&lt;typename T&gt;
struct C
{
     template&lt;typename U&gt; void func(U)
     {

     }
};
int main()
{
    C&lt;int&gt; c;  
    c.template func(5); //this is invalid as per current wording gcc and clang accepts but msvc correctly rejects     
    //c.template func&lt;&gt;(5); //valid as per current wording. All compilers accepts this
}

llvmbot avatar Jan 13 '24 15:01 llvmbot

Wording: https://eel.is/c++draft/temp.names#6

cor3ntin avatar Jan 13 '24 16:01 cor3ntin

https://cplusplus.github.io/CWG/issues/96.html

cor3ntin avatar Jan 13 '24 23:01 cor3ntin

There is existing practice, so we can't simply implement the diagnostic as an error, but doing it as a pedantic wording would be a good idea

https://github.com/search?type=code&auto_enroll=true&q=lang%3Acpp+%2F%5C.template+%5Ba-zA-Z_%5D%5C%28%2F&p=1

cor3ntin avatar Jan 15 '24 07:01 cor3ntin

Should this issue be closed as completed by #78595?

MagentaTreehouse avatar Dec 20 '25 14:12 MagentaTreehouse