<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99892>99892</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Improve error message for template at block scope
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chrchr-github
</td>
</tr>
</table>
<pre>
~~~c++
int main() {
template<typename T>
struct S{};
}
~~~
clang:
~~~
<source>:2:5: error: expected expression
2 | template<typename T>
| ^
~~~
gcc:
~~~
<source>:2:5: error: a template declaration cannot appear at block scope
2 | template<typename T>
| ^~~~~~~~
~~~
msvc:
~~~
<source>(2): error C2951: template declarations are only permitted at global, namespace, or class scope
<source>(2): error C3857: 'S': multiple template parameter lists are not allowed
~~~
https://godbolt.org/z/5cGvn68xv
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyklM-OmzAQxp9muIw2guH_gUM2Waqety9gzCyhNdiyTbrbA89emUSbNqraqo0i8Y014_nNJwbh3DjMzA3kj5AfI7H4k7aNPFl5sg_D6E9LF3W6f2vWdZVAj-EfHyHej7PHSYwzUAVUI5TXc0REz5NRwjOkB_9meBYT4ydIn24ZzttFenwOZeUR0mtx0JtY1_UipBLzAOn-7hjSg9OLlRxuTfcE6T6HdI9srbabeDUsPfdBWHZu1POtOyGUB_w7UtxyIX-6Ixik_Acs8d4Re5ZKWOFHPaMU86w9CmNYWBQeO6XlF3RSG_5P7PXyuwOd3PlP-FQRUP1Ojweq8ySEv5rAobCMelZvaNhOow_WC4-D0p1QQAcMjM4IySHQFqUSzv044e-bp1VehhCofAba5LQoPxrFNyAjrJjYs0U1On9h2nxVSn_l_m7ak_fGBROoBWoH3Xda-Z22A1D7DajN5YfzXFSv56hv0r5OaxFxk5SUFEWeV1l0arIyr4syIaqp61MmGSeySguuqr7qZJ9FY0MxZXFJlBRUULajmPoq57qI65eSqwSymCcxqp1S5yn0jkbnFm7quqopUqJj5bbdJLpsAlFYU9uE_IduGRxk8Tbs7QY_erUt9KUiP-LHyVh95quXEzsnBsYXbW_W_fzORYtVzZ0_27dgJ_UE1IZe18eDsfozSw_UbugOqL3Qnxv6HgAA___xjlSn">