<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99491>99491</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang allows incompatible template constructor for class template argument with default value
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Rush10233
</td>
</tr>
</table>
<pre>
The following code is accepted by clang but rejected by GCC, EDG and MSVC:
```c++
#include<iostream>
template <class K,int NON=0>
struct C
{
int x=0;
C<K>(){x=1;};
};
int main(){
C<int> Cont;
//Cont.x=1
std::cout<<Cont.x<<std::endl;
C<int ,100> Cont_2;
//Cont_2.x=1
std::cout<<Cont_2.x<<std::endl;
}
```
The constructor `C<K>` seems invalid because it does not explain how the class should be instantiated if the default value of `NON` is not taken. For example, in the instantiation of `Cont_2`. As `Cont_2.x` is set to 1, it seems clang will apply the ctor anyway regardless of whether the default argument value is used.
GCC gives a quite puzzling diagnostic about that:
```c++
<source>:6:10: error: expected unqualified-id before ')' token
6 | C<K>(){x=1;};
| ^
Compiler returned: 1
```
And the diagnostic provided by EDG seems more reasonable:
```c++
"<source>", line 6: error: type used as constructor name does not match type "C<K, NON>"
C<K>(){x=1;};
^
1 error detected in the compilation of "<source>".
Compiler returned: 2
```
[https://godbolt.org/z/Gz8cvjaYa](https://godbolt.org/z/Gz8cvjaYa)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVU2P2zYQ_TX0ZbCGRPpjddDBltd7CJoCbVGgp4ASxxYTilT4Ya_31xcUtZa9TZMFDFkkZ95o3swbcufkUSOWZLkly92MB98aW_4RXJtnlLFZbcSl_KtFOBilzFnqIzRGIEgHvGmw9yigvkCjuD5CHTxY_IrNuPtcVYRW8LR7Bq4F_Pbn3xVhG5LtSPb2XGXp1xC6jb-0S5nUjQoCCaukcd4i7wh7Sqceu15xj0BY1SjuHHwitJLaw-ffPx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