Skip to content

Commit

Permalink
Automerge: [Clang] Fix canonicalization of pack indexing types (#123209)
Browse files Browse the repository at this point in the history
A canonicalized pack indexing should refer to a canonicalized pattern

Fixes #123033
  • Loading branch information
cor3ntin authored and github-actions[bot] committed Jan 16, 2025
2 parents b09c1e8 + b311ab0 commit 8c1fbdf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,8 @@ Bug Fixes to C++ Support
- Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda (#GH121274)
- Fixed a crash caused by the incorrect construction of template arguments for CTAD alias guides when type
constraints are applied. (#GH122134)
- Fixed canonicalization of pack indexing types - Clang did not always recognized identical pack indexing. (#GH123033)


Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
8 changes: 5 additions & 3 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6248,16 +6248,18 @@ QualType ASTContext::getPackIndexingType(QualType Pattern, Expr *IndexExpr,
Canonical = getCanonicalType(Expansions[Index]);
} else {
llvm::FoldingSetNodeID ID;
PackIndexingType::Profile(ID, *this, Pattern, IndexExpr, FullySubstituted);
PackIndexingType::Profile(ID, *this, Pattern.getCanonicalType(), IndexExpr,
FullySubstituted);
void *InsertPos = nullptr;
PackIndexingType *Canon =
DependentPackIndexingTypes.FindNodeOrInsertPos(ID, InsertPos);
if (!Canon) {
void *Mem = Allocate(
PackIndexingType::totalSizeToAlloc<QualType>(Expansions.size()),
TypeAlignment);
Canon = new (Mem) PackIndexingType(*this, QualType(), Pattern, IndexExpr,
FullySubstituted, Expansions);
Canon = new (Mem)
PackIndexingType(*this, QualType(), Pattern.getCanonicalType(),
IndexExpr, FullySubstituted, Expansions);
DependentPackIndexingTypes.InsertNode(Canon, InsertPos);
}
Canonical = QualType(Canon, 0);
Expand Down
23 changes: 23 additions & 0 deletions clang/test/SemaCXX/cxx2c-pack-indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,26 @@ namespace GH121242 {
(void)z<X{}>;
}
} // namespace GH121242

namespace GH123033 {
template <class... Types>
requires __is_same_as(Types...[0], int)
void print(double d);

template <class... Types>
requires __is_same_as(Types...[0], int)
void print(double d);

template <class... Types>
Types...[0] convert(double d);

template <class... Types>
Types...[0] convert(double d) {
return static_cast<Types...[0]>(d);
}

void f() {
print<int, int>(12.34);
convert<int, int>(12.34);
}
}

0 comments on commit 8c1fbdf

Please sign in to comment.