This is an archive of the discontinued LLVM Phabricator instance.

MSVC compatibility mode: fix error on unqualified templated base class initialization in case of partial specialization
ClosedPublic

Authored by frederic-tingaud-sonarsource on Jul 28 2022, 7:28 AM.

Details

Summary

I introduced a patch to handle unqualified templated base class initialization in MSVC compatibility mode: https://reviews.llvm.org/rGc894e85fc64dd8d83b460de81080fff93c5ca334
We identified a problem with this patch in the case where the base class is partially specialized, which can lead to triggering an assertion in the case of a mix between types and values.
The minimal test case is:

template <typename Type, int TSize> class Vec {};

template <int TDim> class Index : public Vec<int, TDim> {
  Index() : Vec() {}
};
template class Index<0>;

The detailed problem is that I was using the InjectedClassNameSpecialization, to which the class template arguments were then applied in order. But in the process, we were losing all the partial specializations of the base class and creating an index mismatch between the expected and passed arguments.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2022, 7:28 AM
frederic-tingaud-sonarsource requested review of this revision.Jul 28 2022, 7:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2022, 7:28 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rnk added inline comments.Jul 28 2022, 2:20 PM
clang/lib/Sema/SemaDeclCXX.cpp
4317

Is this cast always safe? Is there a simpler way to check if the base type is a template specialization type?

Use getAs to see through ElaboratedType as recommended by https://reviews.llvm.org/D112374

frederic-tingaud-sonarsource marked an inline comment as done.Jul 29 2022, 2:08 AM

@rnk , does this change answer your points?

rnk accepted this revision.Aug 16 2022, 7:17 AM

Yes, looks good to me, thanks!

This revision is now accepted and ready to land.Aug 16 2022, 7:17 AM