Skip to content

Commit

Permalink
Desugar reflected types in a loop, rather than relying on a fixed order.
Browse files Browse the repository at this point in the history
Closes #41.
  • Loading branch information
katzdm committed May 19, 2024
1 parent e7d7620 commit 3c4d695
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
31 changes: 18 additions & 13 deletions clang/lib/AST/Reflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,25 @@ QualType ReflectionValue::getAsType() const {
assert(getKind() == RK_type && "not a type");

QualType QT = QualType::getFromOpaquePtr(Entity);
if (const auto *LIT = dyn_cast<LocInfoType>(QT))
QT = LIT->getType();
if (const auto *ET = dyn_cast<ElaboratedType>(QT)) {
QualType New = ET->getNamedType();
New.setLocalFastQualifiers(QT.getLocalFastQualifiers());
QT = New;
}
if (const auto *STTPT = dyn_cast<SubstTemplateTypeParmType>(QT))
QT = STTPT->getReplacementType();
if (const auto *RST = dyn_cast<ReflectionSpliceType>(QT))
QT = RST->getUnderlyingType();
if (const auto *DTT = dyn_cast<DecltypeType>(QT))
QT = DTT->desugar();

void *AsPtr;
do {
AsPtr = QT.getAsOpaquePtr();

if (const auto *LIT = dyn_cast<LocInfoType>(QT))
QT = LIT->getType();
if (const auto *ET = dyn_cast<ElaboratedType>(QT)) {
QualType New = ET->getNamedType();
New.setLocalFastQualifiers(QT.getLocalFastQualifiers());
QT = New;
}
if (const auto *STTPT = dyn_cast<SubstTemplateTypeParmType>(QT))
QT = STTPT->getReplacementType();
if (const auto *RST = dyn_cast<ReflectionSpliceType>(QT))
QT = RST->getUnderlyingType();
if (const auto *DTT = dyn_cast<DecltypeType>(QT))
QT = DTT->desugar();
} while (QT.getAsOpaquePtr() != AsPtr);
return QT;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,18 @@ static_assert(template_arguments_of(^WithReflection<^int>).size() == 1);
static_assert(template_arguments_of(^WithReflection<^int>)[0] == ^int);
} // namespace non_auto_non_types

// =======================================
// bb_clang_p2996_issue_41_regression_test
// =======================================

namespace bb_clang_p2996_issue_41_regression_test {
template<class T> struct TCls {};

TCls<int> obj1;
TCls<decltype(obj1)> obj2;

static_assert(has_template_arguments(template_arguments_of(^decltype(obj2))[0]) ==
has_template_arguments(^TCls<int>));
} // namespace bb_clang_p2996_issue_41_regression_test

int main() { }

0 comments on commit 3c4d695

Please sign in to comment.