<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54938>54938</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang vexing parse disambiguation misses template-argument syntactic restrictions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hubert-reinterpretcast
</td>
</tr>
</table>
<pre>
The grammar for _template-argument_ has syntactic constraints such that they cannot be in the form of an _assignment-expression_.
In the following, there is no syntactic ambiguity. The statement within `bar()` is an _expression-statement_. Clang fails to compile, thinking the statement is a _declaration-statement_. GCC seems to work fine.
Compiler Explorer link: https://godbolt.org/z/3GPzerbhM
**SOURCE (`<stdin>`):**
```cpp
namespace N {
template <int> struct A;
extern int X;
}
int foo();
struct AA {
AA();
AA(int);
int &operator<(int);
void operator()(int);
} A;
int p;
void bar() {
AA(N::X)(A < p = foo() > p);
}
```
**ACTUAL OUTPUT:**
```
<stdin>:14:9: error: definition or redeclaration of 'X' not allowed inside a function
AA(N::X)(A < p = foo() > p);
~~~^
1 error generated.
```
**EXPECTED OUTPUT:**
(Clean compile)
**COMPILER INVOCATION:**
```
clang++ -cc1 -fsyntax-only -xc++ -
```
**COMPILER VERSION INFO (`clang++ -v`):**
```
clang version 15.0.0 (https://github.com/llvm/llvm-project.git 353f0a8e43f7e1d12ac96c5e8c37c4d887f51fe2)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVl9v4jgQ_zThZZQIEkLCAw_ZAKtKu6Xq0lXfkJNMwNfEjmynpfvpb5wESultV6c7ZII9Gf_m_wyZLF4X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