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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Fail to compile when defining out-of-class static constexpr member variable of same template class 
        </td>
    </tr>

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

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

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

<pre>
    Related question on StackOverflow: [Define a static constexpr member of same type of a template class](https://stackoverflow.com/questions/72409091/define-a-static-constexpr-member-of-same-type-of-a-template-class)

Clang works well when the static member is not the same type of the template class, or the class is not a template:
```cpp
template <typename T>
struct A {
    static const int constant;
};

template <typename T>
inline constexpr int A<T>::constant = 42;
static_assert(A<double>::constant == 42);

struct B {
    int i;

    static const B constant;
};

inline constexpr B B::constant = { 42 };
static_assert(B::constant.i == 42);
```
https://godbolt.org/z/r1rEcEah8

But fails to compile when both are satisfied:
```cpp
template <typename T>
struct A {
 T data;

    static const A constant;
};
template <typename T>
inline constexpr A<T> A<T>::constant {42};

// template class A<int>;

static_assert(A<int>::constant.data == 42);

int main() {
    // const auto i = A<int>::constant;
    constexpr auto i = A<int>::constant;
}
```
https://godbolt.org/z/hds4G5o5e

(Seems `constexpr` is ignored or require explicit template instantiation)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVcFyozgQ_Rpx6cKFJTBw4GDisMet2pn7loDGKCMQkUQyma_fEjJxbI9nJ1tblYoRqPv1e_2k5saI44hYkKQkySHgs-2VLn48vfVPzyaoVftW_IWSW2zheUZjhRpBjfDF8ubbny-oO6leCdsDScoDdmJE4GAst6KBRo3G4vdJw4BDjRpUB4YPCPZtQrfgYHGYXHJoJDeGJAdCs97ayRC2J7QitDIOSJ2ANo0aCK3WQgyhVUrjKI_yLaFVu-CHPPT44Tt-6PFD1YUOP3T4bsHDFT_0-DQn0YFEe___QfLxCK9KfzPwilLCa48j2B5XgidawsCorP_wkZ57cUWQPoDSy4dlvYaehXC8fQm7yP810-TfvKci7MFBjA7rK2GP_rOxem4s7IGkpX8DABetADFa_8RHS9hpF0kP5-ffARKjdG0-d9el3RP2sGxhe8L2KwgQdoCYvuf31fzNjUFtCc1cVKvmWuJPQ0_RNL8q8ES1vKTqyhBXO28kKH9HgBuGJZQ_IUbSEmIKH-OvCV6FbcQdWmuz_fLyBBxVWytpN0ofCa1-EFrprX5sHnmffSy6nC10XEgDVkGjhklI9I6tle2Ba-dOK0wnsP1fXfYVWm75vwm__7Xwn_Xc6re7xkvLmN521it6dSqXHMIV9nhjtFu_rhsv-uoU-JVjnTcHLkZCM0LzS9-eavIy8dkqWFwC98DeU7vgsyKfiXTC_Bfj9a2J_0hUgpeaZl8QBwPORms5ZBe5y00cR6WxdZeexudZaAT8PknRCHtugvDVCe7udELzoC1Ym7OcB1hsd3kSRxHLo6AvWJam3S6t4y5vs6itMWmzhqc8rVmdJykPREEjyqKc0u2OsSjfsChLdl2-TbMa87zdkjjCgQu5kfJlcMQCYcyMxS7d7lggeY3SLKOQ0sbd_oRSNxV14faH9Xw0JI6kMNacM1hh5TI_fURygIoLeXMKl-kkxiOo2brh4613b1S-cC14LfE8My8tG8xaFlftEraf69OIdNWdfsJJqydsLKHVQtZNzYXvPwEAAP__uOhyfQ">