Skip to content

[clang] implement common sugared type of inst-dependent DecltypeType #67739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ Bug Fixes in This Version
(`#64836 <https://github.com/llvm/llvm-project/issues/64836>`_)
- Clang now allows an ``_Atomic`` qualified integer in a switch statement. Fixes
(`#65557 <https://github.com/llvm/llvm-project/issues/65557>`_)
- Fixes crash when trying to obtain the common sugared type of
`decltype(instantiation-dependent-expr)`.
Fixes (`#67603 <https://github.com/llvm/llvm-project/issues/67603>`_)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12705,7 +12705,6 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,

#define SUGAR_FREE_TYPE(Class) UNEXPECTED_TYPE(Class, "sugar-free")
SUGAR_FREE_TYPE(Builtin)
SUGAR_FREE_TYPE(Decltype)
SUGAR_FREE_TYPE(DeducedTemplateSpecialization)
SUGAR_FREE_TYPE(DependentBitInt)
SUGAR_FREE_TYPE(Enum)
Expand Down Expand Up @@ -12935,6 +12934,14 @@ static QualType getCommonNonSugarTypeNode(ASTContext &Ctx, const Type *X,
TY->getTemplateName()),
As, X->getCanonicalTypeInternal());
}
case Type::Decltype: {
const auto *DX = cast<DecltypeType>(X), *DY = cast<DecltypeType>(Y);
assert(DX->isDependentType());
assert(DY->isDependentType());
assert(Ctx.hasSameExpr(DX->getUnderlyingExpr(), DY->getUnderlyingExpr()));
// As Decltype is not uniqued, building a common type would be wasteful.
return QualType(DX, 0);
}
case Type::DependentName: {
const auto *NX = cast<DependentNameType>(X),
*NY = cast<DependentNameType>(Y);
Expand Down
11 changes: 11 additions & 0 deletions clang/test/SemaCXX/sugar-common-types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,14 @@ namespace PR61419 {
extern const pair<id, id> p;
id t = false ? p.first : p.second;
} // namespace PR61419

namespace GH67603 {
template <class> using A = long;
template <class B> void h() {
using C = B;
using D = B;
N t = 0 ? A<decltype(C())>() : A<decltype(D())>();
// expected-error@-1 {{rvalue of type 'A<decltype(C())>' (aka 'long')}}
}
template void h<int>();
} // namespace GH67603