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

    <tr>
        <th>Summary</th>
        <td>
            clang-10 regression: instantiation of constexpr template callable in C++17 mode despite trivial default init
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          hubert-reinterpretcast
      </td>
    </tr>
</table>

<pre>
    Templated functions that can instantiate such that the specialization satisfies the requirements for a constexpr function are well-formed template definitions. Instantiations that do not satisfy the requirements for a constexpr function are not considered ill-formed for that reason, are constexpr ([DR 1358](https://wg21.link/cwg1358)), but are not callable during constant expression evaluation ([CWG 1872](https://wg21.link/cwg1872)).

Altogether, this means that the following is a well-formed C++17 program that Clang 9 compiled but Clang 10 does not. GCC still compiles it fine (https://godbolt.org/z/YMdq7es7K).

**Source (`<stdin>`):**
```cpp
template <typename T>
struct A {
  constexpr int f() {
    T t;  // cannot be trivial default initialization until P1331
          // (not DR out of Cologne 2019)
    t = T();
    return 42 + t;
  }
};

template <const int &N>
short g(int, char (*)[N] = 0);

template <const int &N>
long g(void *);

const int x = A<int>().f();

extern decltype(g<x>(0)) q;
long q;
```

**Compiler invocation:**
```
clang++ -cc1 -fsyntax-only -std=c++17 -xc++ -
```

**Actual output:**
```
<stdin>:20:6: error: redefinition of 'q' with a different type: 'long' vs 'decltype(g<x>(0))' (aka 'short')
long q;
     ^
<stdin>:19:26: note: previous declaration is here
extern decltype(g<x>(0)) q;
                         ^
1 error generated.
```

**Expected output:**
Successful compile.

**Compiler version info (`clang++ -v`):**
```
clang version 15.0.0 (https://github.com/llvm/llvm-project.git 02db3cfe7d695da8a3119e0305c21a27af6f605c)
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/eJytVk1v4zYQ_TXyhbCgD1u2Dj44TrIoii6KboCip4KSKJkNTTok5Tj76_uGsmVvNpvdLWrItijODN_MvJlRZZqX1YPY7RX3omFtr2svjXbMb7lnNddMaue59hL7zPX1dtjxW6z2opZcyc-cVJjDn2ulcGHTiqdeWrET2jvWGss4q2HXi-PejscwbgV7FkpNIbHD-f6EhDWilVoGKDH7ZYRwgdYYpo0_Hfryk0eSJm3JRlicKi8ASC3Yt4I7o6NsExQudqJsGc1vbv9gaT7H3S3WW-_3LsrXUXaP67nL0lhJ_Yj7-rkLYlkZrg2ren8BwJXilYKvvZW6G86Am4zOEc4RWHHgqh_COxy8-fMDS5eL7EdOJrFwchwlt1GyHn7XyptOIF6WAPmtdGwn-DmsFMfWKGWeCRL2-Bf52UTZDa50wfbWdJbvBq2N4pAu4cJuLxXkyM_hYZogVeAEPI7Zh82GOY9wnyUdk54h04J95U1nmsooHxvbYfUZ379-a54Wwi1-fe1SlNH1yfS2DoaiIonyjfON1FF-RyuEIT-JnVTwMFz1fj88GakHVf-yF5rvBHsg_bDtvO1rz9YsWtwMT9gVKyTS1tLJWXktwNgD81F-w9jgExUUpb4SzFt5QPEQ0XmvPAtsvxRTD7or9nua5-nF2PA5mcJpZApMNAi2adnGKNMhklmSBrqNah4u3cKVAA9oLjtW-N5qNstg7SYgPe9Fi9tToHBzfvx1oEIEgvdRVny8BGtrrGfI2xJbRLN6y4fSoRSU4PFHEDjASq4x_fAByoBaZP9gZMNOVr-0ctE8hoPWsEZoYCIEIm5fBWT4FUcvEJJG1IpYAJkOisdBLRnqiT2NSgHIZTnS6mt6bgbGE1cOpg5Z_hYnTw5Q_Qz1xqZ1nbJp616058ep0eqFTcFv-FWPFTk91mfp74JZ174H-cCcfe_fh3FdSfk6Q2WtC3yZs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