<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/85461>85461</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang doesn't instantiate a constexpr static data member of a class template if it's defined constexpr out of line
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          zygoloid
      </td>
    </tr>
</table>

<pre>
    In order for a class to have a static constexpr data member of the same type as the class, it must be defined out of line so that the type is complete at the point of definition. This implies that the in-class declaration must be `const` and the out-of-class definition must be `constexpr`, because `constexpr` is only permitted on the definition for a variable.

This works fine in Clang for a class, but for a class template, Clang rejects:

```c++
template<typename T> struct A {
    static const A a;
    int n;
};

template<typename T>
constexpr A<T> A<T>::a = {.n = 0};

constexpr int k = A<int>::a.n;
```

[results in](https://godbolt.org/z/x3nzhjs7q)

```console
<source>:9:15: error: constexpr variable 'k' must be initialized by a constant expression
    9 | constexpr int k = A<int>::a.n;
      | ^   ~~~~~~~~~~~
<source>:9:19: note: read of non-constexpr variable 'a' is not allowed in a constant expression
    9 | constexpr int k = A<int>::a.n;
      |                   ^
<source>:2:20: note: declared here
    2 |     static const A a;
      | ^
```

Presumably this is because Clang incorrectly thinks that `A<T>::a` is merely `const` and not `constexpr`, and so doesn't eagerly instantiate it for use in constant evaluation.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VcFy4jgQ_Rpx6YIyEsZw8IFAqNrbHuYHZLvBmsgSK7UzQw777VstE-yEbKr2sC7iuCS9p37drScdozk7xFLkTyI_zHRPrQ_l2_XsrTfNrPLNtfzDgQ8NBjj5ABpqq2ME8tDqVwQNkTSZGmrvIuHvS4BGk4YOuwoD-BNQixB1h0DXC4KOaSCRCLkHQ9D1kaBCaPBkHDbge2KcNQ4heqBWU8IkvIlQ--5ikRBu4xdvXEIkA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