[Clang][Modules] Template argument deduction from base class fails through deep module chain
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Description
Template argument deduction from a derived-to-base conversion fails when the class hierarchy is imported through C++ modules. Functions that accept a base class template and should deduce template arguments from a derived class via implicit derived-to-pointer conversion no longer match after module import.
## Example pattern
```cpp
// In module: three overloads accepting different base class templates
template
T* typeIdentifier(Coordinate::Implementation*);
template
T* typeIdentifier(OffsetCoordinate::Implementation*);
template
T* typeIdentifier(RadixCoordinate::Implementation*);
// Generic entry point - deduces base class from Self
template
auto typeIdentifier() {
Self* self(nullptr);
return typeIdentifier(self); // should match via derived-to-base
}
```
`IDCoordinate::Implementation` inherits (through a deep CRTP chain) from one of the accepted base class templates. Without modules, the compiler correctly deduces template arguments from the base class. Through modules, all overloads report "could not match".
## Error message
```
error: no matching function for call to 'typeIdentifier'
return ::StrongAI::..::Coordinate::Get::typeIdentifier( self );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: candidate template ignored: could not match
'::StrongAI::..::Coordinate::Implementation'
against 'StrongAI::..::IDCoordinate::Implementation'
```
## Reproducer status
A self-contained minimal reproducer has not been achieved. The failure requires the project's full CRTP injection chain (10+ PCM layers through Aspect/PID/Context/Stack). The CRTP base chain is:
```
IDCoordinate::Implementation
: Aspect::template Template
::template TPL
```
The `Aspect::template Template<...>::template TPL<...>` resolves through the module injection chain to eventually inherit from `Coordinate::Implementation`, but this base class is not visible to template argument deduction after PCM deserialization.
## Affected tests
All 4 `persistent_address` test variants fail (same root cause):
- persistent_address
- persistent_address_id_coord
- persistent_address_size_coord
- persistent_address_type_coord
## Relationship to other module serialization bugs
This may be related to other PCM serialization issues where template-related information is lost through deep module chains. In the same project, `explicit` specifiers are also lost on template conversion operators through modules (separate bug).
## Environment
- **Clang version**: 23.0.0git (commit 3392ec8cf17ce90fe0859ae31e86cf48f8fa185d)
- **OS**: macOS 15.4 (Darwin 25.3.0), ARM64
Contributor guide
Research direction
Start by running the four affected persistent_address test variants and tracing the IDCoordinate::Implementation CRTP chain through the Aspect/PID/Context/Stack module layers. Investigate how PCM deserialization represents the inherited Coordinate::Implementation base during template argument deduction; done means the module-imported cases deduce the base template and all four tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100