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

    <tr>
        <th>Summary</th>
        <td>
            Default template argument for variable template checked before use
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    See https://compiler-explorer.com/z/s9Y7snsxY and https://eel.is/c++draft/temp.inst#7.sentence-2.
> A default template argument for a variable template is implicitly instantiated when the variable template is referenced in a context that requires the value of the default argument[.](https://eel.is/c++draft/temp.inst#7.sentence-2)
```C++
extern const int i;
template<int j = i> constexpr int k = j;
constexpr int i = 0;
static_assert(k<> == 0);
```
```
<source>:2:18: error: non-type template argument is not a constant expression
template<int j = i> constexpr int k = j;
                 ^
<source>:2:18: note: initializer of 'i' is unknown
<source>:1:18: note: declared here
extern const int i;
                 ^
<source>:4:15: error: too few template arguments for variable template 'k'
static_assert(k<> == 0);
              ^
<source>:2:35: note: template is declared here
template<int j = i> constexpr int k = j;
~~~~~~~~~~~~~~~~~~~               ^
2 errors generated.
Compiler returned: 1
```
Using `auto` works: https://compiler-explorer.com/z/ca6xxn1cf.
```C++
extern const int i;
template<auto j = i> constexpr int k = j;
constexpr int i = 0;
static_assert(k<> == 0);
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVUtzmzAQ_jXiojEDwmB84JDYbmd66kynh5w6AhZQLEuuJGInv74rsJM4dpvXoYwEkvahT9-ullLX98UPANo5t7UkuSLsC7ZKb7ZCgpnAfiu1ARPiCq4_YLfzm5lVdn9Duapf2AHIUFjvgLBrbLXhjcOpg802FMriOJmFFpQDVcGEhSRakuiKJCt6RWtoeC8d9cqSO6DctP0GdWmjDeX0jhvBSwlPCsJSgUNRCSfvqffPlRMoqemuA0VdB5etDDRgPIQardB1pRHRHrfuuEPh714YsAdz2QPVzTA5IjwCI-l1SNIlYfnnaCBsfiAii8a2GA3HVUQGRnmQ1iFe7CQ5iI6HIsnCC24pSZZevBq1MXxmsFgPgttHu1OpGKTRoxR5dKL6xa0Fg1jzNbr3PlFrVES8R91HyJenycLq3lQIcIX0MOxxji8KxmjjB0qribvfwoWwY6CUdmN4htBSjxisFVp97vj05UPS1SuAEQn4r1ACU0yKBzA-LQibCewea6_WSu_URT_xmZ8aKskNJmCHmfhqnN8MeOo3Sk8YdlrTBnbnBNvhYp1fEDzPGvv7c-HtnCbpcy6eX80LvHw0ymS2-lj7G9dsJNXSFhQYX2cOBWxxqJdYO1xvFNT-VPHFG_HTCtVSnPLeafzQnTZrXzreUYIrnu33Kq6a8PNlw8P4r3UjgCLOsjzO04jFQV0k9TyZ88BhTYdi-c9_wnnqVh1Ua0yeElAOtLcQ9EYWp9S2wnV9eeBTyrvjZ7I1-hYqX6mFtT34Cp7m8ykLuiKfpcCyumZRyvN6HrEpZxUk0OSsjGvggeQlSFvgL4EwpvC6DS5wjD-IQBQsYiz2TzZNpnEYQZklJWuqecNnEeNkGsGGCxl6HKE2bWCKAVLZtxaFUlhnn4TIsGgVwLAd-scgdtoU33QHcvX1ezDsXQzY_wBcCF__">