<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58080>58080</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Confusing "undefined constructor cannot be used in a constant expression" error in nested class
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zmodem
</td>
</tr>
</table>
<pre>
Consider (https://godbolt.org/z/M4sPT137a):
```
$ cat /tmp/a.cc
struct S {
static constexpr struct T {
constexpr T() {}
} t = {};
};
$ clang -c /tmp/a.cc
/tmp/a.cc:4:7: error: constexpr variable 't' must be initialized by a constant expression
} t = {};
^ ~~
/tmp/a.cc:4:11: note: undefined constructor 'T' cannot be used in a constant expression
} t = {};
^
/tmp/a.cc:3:19: note: declared here
constexpr T() {}
^
1 error generated.
```
This is confusing: the definition of the constructor is right there on line 3, clang is even pointing it out in the note.
I suppose it's considered undefined for some technical reason, and perhaps clang could explain it?
GCC is more terse but does include a hint:
```
error: 'constexpr S::T::T()' called in a constant expression before its definition is complete
```
Aha, maybe it won't be complete until the end of the outermost class definition? It would be cool if the compiler could say so.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVdtunDAQ_Rp4sbICm12yDzykuVR5qFQp-wMGD-DK2Mg2aZOv74zZ7W6qNGpVZAO2xzPH58xA69RLc-ts0Ao8y_j1GOMcMnGT8Qdsg1OtM3Hj_ICjV-xfqvD1UIpaZnxPZsVdVpzuu-LY1iGvWCcjOn2I04x3uem6dSlEv3SRPbGs_rTOMLxClFF3rEM0EX7Mnh3NDm_N6DrbHBAzQkkm9d3ZCgcMY4u704o4unjzThCNtAO76t7D-XZK3FTYa-wMvHeeXs5AnqXXsjWAfuqInU1LiKwFpq2OWhr9Coq1L0yue6SNjPZBCNrZv8C9Hjzb3ieje2p_xFiWhM26CPRcrIJeWwyfIhOnjrSuDwSzkxYNC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