)cpp",
"DeclRefExpr"},
{"[[decltype^(1)]] b;", "DecltypeTypeLoc"}, // Not the VarDecl.
- // decltype(auto) is an AutoTypeLoc!
- {"[[de^cltype(a^uto)]] a = 1;", "AutoTypeLoc"},
// Objective-C nullability attributes.
{
NamedDecl *FoundDecl;
SourceLocation LAngleLoc;
SourceLocation RAngleLoc;
-
- // For decltype(auto).
- SourceLocation RParenLoc;
};
class AutoTypeLoc
return getTypePtr()->getKeyword();
}
- bool isDecltypeAuto() const { return getTypePtr()->isDecltypeAuto(); }
- SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
- void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
-
bool isConstrained() const {
return getTypePtr()->isConstrained();
}
}
SourceRange getLocalSourceRange() const {
- return {isConstrained()
- ? (getNestedNameSpecifierLoc()
- ? getNestedNameSpecifierLoc().getBeginLoc()
- : (getTemplateKWLoc().isValid() ? getTemplateKWLoc()
- : getConceptNameLoc()))
- : getNameLoc(),
- isDecltypeAuto() ? getRParenLoc() : getNameLoc()};
+ return{
+ isConstrained()
+ ? (getNestedNameSpecifierLoc()
+ ? getNestedNameSpecifierLoc().getBeginLoc()
+ : (getTemplateKWLoc().isValid()
+ ? getTemplateKWLoc()
+ : getConceptNameLoc()))
+ : getNameLoc(),
+ getNameLoc()
+ };
}
void copy(AutoTypeLoc Loc) {
setFoundDecl(nullptr);
setRAngleLoc(Loc);
setLAngleLoc(Loc);
- setRParenLoc(Loc);
TemplateSpecializationTypeLoc::initializeArgLocs(Context, getNumArgs(),
getTypePtr()->getArgs(),
getArgInfos(), Loc);
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeLocVisitor.h"
#include "clang/Basic/PartialDiagnostic.h"
-#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/DeclSpec.h"
DS.getTypeSpecType() == TST_auto_type ||
DS.getTypeSpecType() == TST_unspecified);
TL.setNameLoc(DS.getTypeSpecTypeLoc());
- if (DS.getTypeSpecType() == TST_decltype_auto)
- TL.setRParenLoc(DS.getTypeofParensRange().getEnd());
if (!DS.isConstrainedAuto())
return;
TemplateIdAnnotation *TemplateId = DS.getRepAsTemplateId();
TL.setArgLocInfo(i, Reader.readTemplateArgumentLocInfo(
TL.getTypePtr()->getArg(i).getKind()));
}
- if (Reader.readBool())
- TL.setRParenLoc(readSourceLocation());
}
void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc(
Record.AddTemplateArgumentLocInfo(TL.getTypePtr()->getArg(I).getKind(),
TL.getArgLocInfo(I));
}
- Record.push_back(TL.isDecltypeAuto());
- if (TL.isDecltypeAuto())
- Record.AddSourceLocation(TL.getRParenLoc());
}
void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc(
// CHECK-NEXT: "tokLen": 8
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
-// CHECK-NEXT: "offset": 718,
-// CHECK-NEXT: "col": 24,
-// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: "offset": 705,
+// CHECK-NEXT: "col": 11,
+// CHECK-NEXT: "tokLen": 8
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
template <decltype(auto)>
// CHECK: ClassTemplateDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+2]]:11> col:8 U
-// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11, col:24> col:25 'decltype(auto)' depth 0 index 0
+// CHECK-NEXT: NonTypeTemplateParmDecl 0x{{[^ ]*}} <line:[[@LINE-2]]:11> col:25 'decltype(auto)' depth 0 index 0
struct U {};
template <typename Ty>
verify(Target2->getSourceRange(), Code.range("full2"));
}
-TEST(TypeLoc, AutoTypeLocRange) {
- RangeVerifier<TypeLoc> Verifier;
- Verifier.expectRange(1, 1, 1, 14);
- EXPECT_TRUE(Verifier.match("decltype(auto) a = 1;", typeLoc(loc(autoType())),
- Lang_CXX11));
-}
-
TEST(TypeLoc, LongDoubleRange) {
RangeVerifier<TypeLoc> Verifier;
Verifier.expectRange(1, 1, 1, 6);