llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

`getTypeSourceInfo()->getType()` and `getType()` are inconsistent for a constrained variable

Open tJener opened this issue 1 year ago • 3 comments

#include <concepts>

void find(auto value) {
  std::integral auto var = value;
}

Calling getTypeSourceInfo()->getType() and getType() result in two unique AutoTypes. If I have something like

v.getTypeSourceInfo()->getType()->dump();
v.getType()->dump();

the output is

AutoType 0x141b92c00 'integral auto' undeduced
`-Concept 0x141995a88 'integral'
AutoType 0x141b92d30 'integral auto' dependent
`-Concept 0x141995a88 'integral'

tJener avatar Nov 07 '25 15:11 tJener

@llvm/issue-subscribers-clang-frontend

Author: Eric Li (tJener)

```c++ #include <concepts>

void find(auto value) { std::integral auto var = value; }


Calling `getTypeSourceInfo()-&gt;getType()` and `getType()` result in two unique `AutoType`s. If I have something like
```c++
v.getTypeSourceInfo()-&gt;getType()-&gt;dump();
v.getType()-&gt;dump();

the output is

AutoType 0x141b92c00 'integral auto' undeduced
`-Concept 0x141995a88 'integral'
AutoType 0x141b92d30 'integral auto' dependent
`-Concept 0x141995a88 'integral'

llvmbot avatar Nov 07 '25 15:11 llvmbot

CC @mizvekov

shafik avatar Nov 13 '25 02:11 shafik

Not a bug, this difference is expected.

The TypeSourceInfo is never deduced, it always contains the undeduced type. That explains the first dump:

AutoType 0x141b92c00 'integral auto' undeduced
`-Concept 0x141995a88 'integral'

Here the variable was deduced-as-dependent, which is expected since the initializer is dependent, so that explains your second dump:

AutoType 0x141b92d30 'integral auto' dependent
`-Concept 0x141995a88 'integral'

We keep track of these things separately because the deduced type is never used in template instantiation, we always perform deduction again from scratch, using the now instantiated initializer.

This is needed because a dependent type can not always be instantiated, because it may contain a DependentTy.

If we kept only the deduced type around, we would need to transform it back to undeduced when instantiating, so we save the undeduced type to avoid that.

mizvekov avatar Feb 12 '26 18:02 mizvekov