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

    <tr>
        <th>Summary</th>
        <td>
            Sometimes clang diagnostics has missing "requested here" elements of template instantiation
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          geza-herman
      </td>
    </tr>
</table>

<pre>
    Look at this (intentionally) non-compiling example:
```c++
template <typename T>
T level0(T t) {
    return t + 1;
}

template <typename T>
T level1(T t) {
    return level0(t);
}

template <typename T>
T level2(T t) {
    return level1(t);
}

int main() {
    level2(nullptr);
}
```

`T` is deduced as `nullptr_t`, `level0` cannot add `1` to it, so clang emits this useful error, listing the whole "instantiation stack":

```
t.cpp:3:14: error: invalid operands to binary expression ('std::nullptr_t' and 'int')
    3 | return t + 1;
      |            ~ ^ ~
t.cpp:8:12: note: in instantiation of function template specialization 'level0<std::nullptr_t>' requested here
    8 |     return level0(t);
      | ^
t.cpp:13:12: note: in instantiation of function template specialization 'level1<std::nullptr_t>' requested here
   13 |     return level1(t);
 |            ^
t.cpp:17:5: note: in instantiation of function template specialization 'level2<std::nullptr_t>' requested here
   17 | level2(nullptr);
      |     ^
```

Now, if you change the return type of `level1` and `level2` to `auto`, clang no longer lists the whole stack, it only shows a truncated version, it is no longer possible to know where `level0` instantiated from:
```
t.cpp:3:14: error: invalid operands to binary expression ('std::nullptr_t' and 'int')
    3 | return t + 1;
      |            ~ ^ ~
t.cpp:8:12: note: in instantiation of function template specialization 'level0<std::nullptr_t>' requested here
    8 |     return level0(t);
      | ^
```

It seems that functions which call a function with `auto` return type are omitted from the stack. But the interesting thing is that if the return type of `level0` is changed to `auto` as well (so all 3 functions return `auto`), then the whole stack is shown again.

(Debian clang version 20.0.0 (++20241008102056+4d218caa7716-1~exp1))
</pre>
<img width="1px" height="1px" alt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