Author: cor3ntin Date: 2024-02-21T08:46:47+01:00 New Revision: 351e4fa2bfe5b13073c1675a1b1693ea766c1e25
URL: https://github.com/llvm/llvm-project/commit/351e4fa2bfe5b13073c1675a1b1693ea766c1e25 DIFF: https://github.com/llvm/llvm-project/commit/351e4fa2bfe5b13073c1675a1b1693ea766c1e25.diff LOG: [Clang] Fix assert when transforming a pack indexing type. (#82234) When a pack in a pack indexing specifier cannot be immediately expanded, we were creating an incomplete TypeLoc (causing assertion failure). As we do not keep track of typelocs of expanded elements, we create a trivial typeloc Fixes #81697 Added: Modified: clang/lib/Sema/TreeTransform.h clang/test/SemaCXX/cxx2c-pack-indexing.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index a32a585531873a..7389a48fe56fcc 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6561,7 +6561,11 @@ TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB, return QualType(); if (!ShouldExpand) { Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); - QualType Pack = getDerived().TransformType(T); + // FIXME: should we keep TypeLoc for individual expansions in + // PackIndexingTypeLoc? + TypeSourceInfo *TI = + SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc()); + QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc()); if (Pack.isNull()) return QualType(); if (NotYetExpanded) { diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp index 625a56031598b7..e13635383b6ca6 100644 --- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp +++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp @@ -135,3 +135,22 @@ using Splice = typename SpliceImpl<Tl, Il>::type; using type = Splice<TL<char, short, long, double>, IL<1, 2>>; static_assert(is_same<type, TL<short, long>>); } + + +namespace GH81697 { + +template<class... Ts> struct tuple { + int __x0; +}; + +template<auto I, class... Ts> +Ts...[I]& get(tuple<Ts...>& t) { + return t.__x0; +} + +void f() { + tuple<int> x; + get<0>(x); +} + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits