aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/DeclSpec.cpp
diff options
context:
space:
mode:
authorcor3ntin <corentinjabot@gmail.com>2024-01-27 10:23:38 +0100
committerGitHub <noreply@github.com>2024-01-27 10:23:38 +0100
commitad1a65fcacda8794e2f1fa3e1dec1c1b7813422c (patch)
treeee68f0f3f24c7dfaa09a2b75dc5427d7f11b6a15 /clang/lib/Sema/DeclSpec.cpp
parent1f13203029333ac99cc9844b8b6915aae3fc0902 (diff)
downloadllvm-ad1a65fcacda8794e2f1fa3e1dec1c1b7813422c.zip
llvm-ad1a65fcacda8794e2f1fa3e1dec1c1b7813422c.tar.gz
llvm-ad1a65fcacda8794e2f1fa3e1dec1c1b7813422c.tar.bz2
[Clang][C++26] Implement Pack Indexing (P2662R3). (#72644)
Implements https://isocpp.org/files/papers/P2662R3.pdf The feature is exposed as an extension in older language modes. Mangling is not yet supported and that is something we will have to do before release.
Diffstat (limited to 'clang/lib/Sema/DeclSpec.cpp')
-rw-r--r--clang/lib/Sema/DeclSpec.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 781f24c..313f073 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -374,6 +374,7 @@ bool Declarator::isDeclarationOfFunction() const {
case TST_void:
case TST_wchar:
case TST_BFloat16:
+ case TST_typename_pack_indexing:
#define GENERIC_IMAGE_TYPE(ImgType, Id) case TST_##ImgType##_t:
#include "clang/Basic/OpenCLImageTypes.def"
return false;
@@ -585,6 +586,8 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TST T,
case DeclSpec::TST_struct: return "struct";
case DeclSpec::TST_interface: return "__interface";
case DeclSpec::TST_typename: return "type-name";
+ case DeclSpec::TST_typename_pack_indexing:
+ return "type-name-pack-indexing";
case DeclSpec::TST_typeofType:
case DeclSpec::TST_typeofExpr: return "typeof";
case DeclSpec::TST_typeof_unqualType:
@@ -775,6 +778,15 @@ bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc,
TSTLoc = TagKwLoc;
TSTNameLoc = TagNameLoc;
TypeSpecOwned = false;
+
+ if (T == TST_typename_pack_indexing) {
+ // we got there from a an annotation. Reconstruct the type
+ // Ugly...
+ QualType QT = Rep.get();
+ const PackIndexingType *LIT = cast<PackIndexingType>(QT);
+ TypeRep = ParsedType::make(LIT->getPattern());
+ PackIndexingExpr = LIT->getIndexExpr();
+ }
return false;
}
@@ -973,6 +985,15 @@ bool DeclSpec::SetBitIntType(SourceLocation KWLoc, Expr *BitsExpr,
return false;
}
+void DeclSpec::SetPackIndexingExpr(SourceLocation EllipsisLoc,
+ Expr *IndexingExpr) {
+ assert(TypeSpecType == TST_typename &&
+ "pack indexing can only be applied to typename");
+ TypeSpecType = TST_typename_pack_indexing;
+ PackIndexingExpr = IndexingExpr;
+ this->EllipsisLoc = EllipsisLoc;
+}
+
bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
unsigned &DiagID, const LangOptions &Lang) {
// Duplicates are permitted in C99 onwards, but are not permitted in C89 or