2012-11-07 01:31:40 +08:00
|
|
|
//===- unittest/AST/SourceLocationTest.cpp - AST source loc unit tests ----===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-11-07 01:31:40 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains tests for SourceLocation and SourceRange fields
|
|
|
|
// in AST nodes.
|
|
|
|
//
|
|
|
|
// FIXME: In the long-term, when we test more than source locations, we may
|
|
|
|
// want to have a unit test file for an AST node (or group of related nodes),
|
|
|
|
// rather than a unit test file for source locations for all AST nodes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "MatchVerifier.h"
|
2012-11-07 01:31:40 +08:00
|
|
|
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
2012-12-04 17:45:34 +08:00
|
|
|
#include "clang/ASTMatchers/ASTMatchers.h"
|
2012-11-07 01:31:40 +08:00
|
|
|
#include "clang/Tooling/Tooling.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace ast_matchers {
|
|
|
|
|
2013-01-31 21:10:40 +08:00
|
|
|
// FIXME: Pull the *Verifier tests into their own test file.
|
2012-11-07 01:31:40 +08:00
|
|
|
|
|
|
|
TEST(MatchVerifier, ParseError) {
|
|
|
|
LocationVerifier<VarDecl> Verifier;
|
|
|
|
Verifier.expectLocation(1, 1);
|
|
|
|
EXPECT_FALSE(Verifier.match("int i", varDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MatchVerifier, NoMatch) {
|
|
|
|
LocationVerifier<VarDecl> Verifier;
|
|
|
|
Verifier.expectLocation(1, 1);
|
|
|
|
EXPECT_FALSE(Verifier.match("int i;", recordDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MatchVerifier, WrongType) {
|
|
|
|
LocationVerifier<RecordDecl> Verifier;
|
|
|
|
Verifier.expectLocation(1, 1);
|
|
|
|
EXPECT_FALSE(Verifier.match("int i;", varDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LocationVerifier, WrongLocation) {
|
|
|
|
LocationVerifier<VarDecl> Verifier;
|
|
|
|
Verifier.expectLocation(1, 1);
|
|
|
|
EXPECT_FALSE(Verifier.match("int i;", varDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(RangeVerifier, WrongRange) {
|
|
|
|
RangeVerifier<VarDecl> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 1);
|
|
|
|
EXPECT_FALSE(Verifier.match("int i;", varDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
class LabelDeclRangeVerifier : public RangeVerifier<LabelStmt> {
|
|
|
|
protected:
|
2015-04-11 10:00:23 +08:00
|
|
|
SourceRange getRange(const LabelStmt &Node) override {
|
2012-11-07 01:31:40 +08:00
|
|
|
return Node.getDecl()->getSourceRange();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(LabelDecl, Range) {
|
|
|
|
LabelDeclRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 12, 1, 12);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f() { l: return; }", labelStmt()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LabelStmt, Range) {
|
|
|
|
RangeVerifier<LabelStmt> Verifier;
|
|
|
|
Verifier.expectRange(1, 12, 1, 15);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f() { l: return; }", labelStmt()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ParmVarDecl, KNRLocation) {
|
|
|
|
LocationVerifier<ParmVarDecl> Verifier;
|
|
|
|
Verifier.expectLocation(1, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(i) {}", varDecl(), Lang_C));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ParmVarDecl, KNRRange) {
|
|
|
|
RangeVerifier<ParmVarDecl> Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(i) {}", varDecl(), Lang_C));
|
|
|
|
}
|
|
|
|
|
2012-11-08 01:17:07 +08:00
|
|
|
TEST(CXXNewExpr, ArrayRange) {
|
|
|
|
RangeVerifier<CXXNewExpr> Verifier;
|
|
|
|
Verifier.expectRange(1, 12, 1, 22);
|
2015-09-17 21:30:52 +08:00
|
|
|
EXPECT_TRUE(Verifier.match("void f() { new int[10]; }", cxxNewExpr()));
|
2012-11-08 01:17:07 +08:00
|
|
|
}
|
|
|
|
|
2012-11-09 06:53:48 +08:00
|
|
|
TEST(CXXNewExpr, ParenRange) {
|
|
|
|
RangeVerifier<CXXNewExpr> Verifier;
|
|
|
|
Verifier.expectRange(1, 12, 1, 20);
|
2015-09-17 21:30:52 +08:00
|
|
|
EXPECT_TRUE(Verifier.match("void f() { new int(); }", cxxNewExpr()));
|
2012-11-09 06:53:48 +08:00
|
|
|
}
|
|
|
|
|
2012-11-08 21:52:58 +08:00
|
|
|
TEST(MemberExpr, ImplicitMemberRange) {
|
|
|
|
RangeVerifier<MemberExpr> Verifier;
|
|
|
|
Verifier.expectRange(2, 30, 2, 30);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct S { operator int() const; };\n"
|
|
|
|
"int foo(const S& s) { return s; }",
|
2015-05-01 10:04:32 +08:00
|
|
|
memberExpr()));
|
|
|
|
}
|
|
|
|
|
|
|
|
class MemberExprArrowLocVerifier : public RangeVerifier<MemberExpr> {
|
2015-04-11 10:00:23 +08:00
|
|
|
protected:
|
|
|
|
SourceRange getRange(const MemberExpr &Node) override {
|
2015-05-01 10:04:32 +08:00
|
|
|
return Node.getOperatorLoc();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(MemberExpr, ArrowRange) {
|
|
|
|
MemberExprArrowLocVerifier Verifier;
|
|
|
|
Verifier.expectRange(2, 19, 2, 19);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct S { int x; };\n"
|
|
|
|
"void foo(S *s) { s->x = 0; }",
|
|
|
|
memberExpr()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemberExpr, MacroArrowRange) {
|
|
|
|
MemberExprArrowLocVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 24, 1, 24);
|
|
|
|
EXPECT_TRUE(Verifier.match("#define MEMBER(a, b) (a->b)\n"
|
|
|
|
"struct S { int x; };\n"
|
|
|
|
"void foo(S *s) { MEMBER(s, x) = 0; }",
|
|
|
|
memberExpr()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MemberExpr, ImplicitArrowRange) {
|
|
|
|
MemberExprArrowLocVerifier Verifier;
|
|
|
|
Verifier.expectRange(0, 0, 0, 0);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct S { int x; void Test(); };\n"
|
|
|
|
"void S::Test() { x = 1; }",
|
|
|
|
memberExpr()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(VarDecl, VMTypeFixedVarDeclRange) {
|
|
|
|
RangeVerifier<VarDecl> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 23);
|
2012-11-08 22:44:42 +08:00
|
|
|
EXPECT_TRUE(Verifier.match("int a[(int)(void*)1234];",
|
|
|
|
varDecl(), Lang_C89));
|
|
|
|
}
|
|
|
|
|
2016-10-22 05:13:56 +08:00
|
|
|
TEST(TypeLoc, IntRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 1);
|
|
|
|
EXPECT_TRUE(Verifier.match("int a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, LongRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 1);
|
|
|
|
EXPECT_TRUE(Verifier.match("long a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, LongDoubleRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 6);
|
|
|
|
EXPECT_TRUE(Verifier.match("long double a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, DoubleLongRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("double long a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, LongIntRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 6);
|
|
|
|
EXPECT_TRUE(Verifier.match("long int a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, IntLongRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 5);
|
|
|
|
EXPECT_TRUE(Verifier.match("int long a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, UnsignedIntRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 10);
|
|
|
|
EXPECT_TRUE(Verifier.match("unsigned int a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, IntUnsignedRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 5);
|
|
|
|
EXPECT_TRUE(Verifier.match("int unsigned a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, LongLongRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 6);
|
|
|
|
EXPECT_TRUE(Verifier.match("long long a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, UnsignedLongLongRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 15);
|
|
|
|
EXPECT_TRUE(Verifier.match("unsigned long long a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, LongUnsignedLongRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 15);
|
|
|
|
EXPECT_TRUE(Verifier.match("long unsigned long a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, LongLongUnsignedRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 11);
|
|
|
|
EXPECT_TRUE(Verifier.match("long long unsigned a;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, ConstLongLongRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 7, 1, 12);
|
|
|
|
EXPECT_TRUE(Verifier.match("const long long a = 0;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, LongConstLongRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 12);
|
|
|
|
EXPECT_TRUE(Verifier.match("long const long a = 0;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TypeLoc, LongLongConstRange) {
|
|
|
|
RangeVerifier<TypeLoc> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 6);
|
|
|
|
EXPECT_TRUE(Verifier.match("long long const a = 0;", typeLoc()));
|
|
|
|
}
|
|
|
|
|
2012-11-08 22:44:42 +08:00
|
|
|
TEST(CXXConstructorDecl, NoRetFunTypeLocRange) {
|
|
|
|
RangeVerifier<CXXConstructorDecl> Verifier;
|
|
|
|
Verifier.expectRange(1, 11, 1, 13);
|
|
|
|
EXPECT_TRUE(Verifier.match("class C { C(); };", functionDecl()));
|
|
|
|
}
|
|
|
|
|
2015-03-24 05:43:28 +08:00
|
|
|
TEST(CXXConstructorDecl, DefaultedCtorLocRange) {
|
|
|
|
RangeVerifier<CXXConstructorDecl> Verifier;
|
|
|
|
Verifier.expectRange(1, 11, 1, 23);
|
|
|
|
EXPECT_TRUE(Verifier.match("class C { C() = default; };", functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CXXConstructorDecl, DeletedCtorLocRange) {
|
|
|
|
RangeVerifier<CXXConstructorDecl> Verifier;
|
|
|
|
Verifier.expectRange(1, 11, 1, 22);
|
|
|
|
EXPECT_TRUE(Verifier.match("class C { C() = delete; };", functionDecl()));
|
|
|
|
}
|
|
|
|
|
2013-02-05 13:55:57 +08:00
|
|
|
TEST(CompoundLiteralExpr, CompoundVectorLiteralRange) {
|
|
|
|
RangeVerifier<CompoundLiteralExpr> Verifier;
|
|
|
|
Verifier.expectRange(2, 11, 2, 22);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"typedef int int2 __attribute__((ext_vector_type(2)));\n"
|
|
|
|
"int2 i2 = (int2){1, 2};", compoundLiteralExpr()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CompoundLiteralExpr, ParensCompoundVectorLiteralRange) {
|
|
|
|
RangeVerifier<CompoundLiteralExpr> Verifier;
|
2013-04-06 04:14:50 +08:00
|
|
|
Verifier.expectRange(2, 20, 2, 31);
|
2013-02-05 13:55:57 +08:00
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"typedef int int2 __attribute__((ext_vector_type(2)));\n"
|
2013-04-06 04:14:50 +08:00
|
|
|
"constant int2 i2 = (int2)(1, 2);",
|
2013-02-05 13:55:57 +08:00
|
|
|
compoundLiteralExpr(), Lang_OpenCL));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(InitListExpr, VectorLiteralListBraceRange) {
|
|
|
|
RangeVerifier<InitListExpr> Verifier;
|
|
|
|
Verifier.expectRange(2, 17, 2, 22);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"typedef int int2 __attribute__((ext_vector_type(2)));\n"
|
|
|
|
"int2 i2 = (int2){1, 2};", initListExpr()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(InitListExpr, VectorLiteralInitListParens) {
|
|
|
|
RangeVerifier<InitListExpr> Verifier;
|
2013-04-06 04:14:50 +08:00
|
|
|
Verifier.expectRange(2, 26, 2, 31);
|
2013-02-05 13:55:57 +08:00
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"typedef int int2 __attribute__((ext_vector_type(2)));\n"
|
2013-04-06 04:14:50 +08:00
|
|
|
"constant int2 i2 = (int2)(1, 2);", initListExpr(), Lang_OpenCL));
|
2013-02-05 13:55:57 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 19:27:57 +08:00
|
|
|
class TemplateAngleBracketLocRangeVerifier : public RangeVerifier<TypeLoc> {
|
|
|
|
protected:
|
2015-04-11 10:00:23 +08:00
|
|
|
SourceRange getRange(const TypeLoc &Node) override {
|
2013-06-07 19:27:57 +08:00
|
|
|
TemplateSpecializationTypeLoc T =
|
2013-06-08 04:31:48 +08:00
|
|
|
Node.getUnqualifiedLoc().castAs<TemplateSpecializationTypeLoc>();
|
2013-06-07 19:27:57 +08:00
|
|
|
assert(!T.isNull());
|
|
|
|
return SourceRange(T.getLAngleLoc(), T.getRAngleLoc());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(TemplateSpecializationTypeLoc, AngleBracketLocations) {
|
|
|
|
TemplateAngleBracketLocRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(2, 8, 2, 10);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"template<typename T> struct A {}; struct B{}; void f(\n"
|
|
|
|
"const A<B>&);",
|
|
|
|
loc(templateSpecializationType())));
|
|
|
|
}
|
|
|
|
|
2013-06-18 06:35:10 +08:00
|
|
|
TEST(CXXNewExpr, TypeParenRange) {
|
|
|
|
RangeVerifier<CXXNewExpr> Verifier;
|
|
|
|
Verifier.expectRange(1, 10, 1, 18);
|
2015-09-17 21:30:52 +08:00
|
|
|
EXPECT_TRUE(Verifier.match("int* a = new (int);", cxxNewExpr()));
|
2013-06-18 06:35:10 +08:00
|
|
|
}
|
|
|
|
|
2013-07-07 02:54:58 +08:00
|
|
|
class UnaryTransformTypeLocParensRangeVerifier : public RangeVerifier<TypeLoc> {
|
|
|
|
protected:
|
2015-04-11 10:00:23 +08:00
|
|
|
SourceRange getRange(const TypeLoc &Node) override {
|
2013-07-07 02:54:58 +08:00
|
|
|
UnaryTransformTypeLoc T =
|
|
|
|
Node.getUnqualifiedLoc().castAs<UnaryTransformTypeLoc>();
|
|
|
|
assert(!T.isNull());
|
|
|
|
return SourceRange(T.getLParenLoc(), T.getRParenLoc());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(UnaryTransformTypeLoc, ParensRange) {
|
|
|
|
UnaryTransformTypeLocParensRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(3, 26, 3, 28);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"template <typename T>\n"
|
|
|
|
"struct S {\n"
|
|
|
|
"typedef __underlying_type(T) type;\n"
|
|
|
|
"};",
|
|
|
|
loc(unaryTransformType())));
|
|
|
|
}
|
|
|
|
|
2013-07-07 14:41:54 +08:00
|
|
|
TEST(CXXFunctionalCastExpr, SourceRange) {
|
|
|
|
RangeVerifier<CXXFunctionalCastExpr> Verifier;
|
|
|
|
Verifier.expectRange(2, 10, 2, 14);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"int foo() {\n"
|
|
|
|
" return int{};\n"
|
|
|
|
"}",
|
2015-09-17 21:30:52 +08:00
|
|
|
cxxFunctionalCastExpr(), Lang_CXX11));
|
2013-07-07 14:41:54 +08:00
|
|
|
}
|
|
|
|
|
2014-02-22 10:59:41 +08:00
|
|
|
TEST(CXXConstructExpr, SourceRange) {
|
|
|
|
RangeVerifier<CXXConstructExpr> Verifier;
|
|
|
|
Verifier.expectRange(3, 14, 3, 19);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"struct A { A(int, int); };\n"
|
|
|
|
"void f(A a);\n"
|
|
|
|
"void g() { f({0, 0}); }",
|
2015-09-17 21:30:52 +08:00
|
|
|
cxxConstructExpr(), Lang_CXX11));
|
2014-02-22 10:59:41 +08:00
|
|
|
}
|
|
|
|
|
2013-09-07 13:49:53 +08:00
|
|
|
TEST(CXXTemporaryObjectExpr, SourceRange) {
|
|
|
|
RangeVerifier<CXXTemporaryObjectExpr> Verifier;
|
|
|
|
Verifier.expectRange(2, 6, 2, 12);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"struct A { A(int, int); };\n"
|
|
|
|
"A a( A{0, 0} );",
|
2015-09-17 21:30:52 +08:00
|
|
|
cxxTemporaryObjectExpr(), Lang_CXX11));
|
2013-09-07 13:49:53 +08:00
|
|
|
}
|
|
|
|
|
2013-07-07 14:41:54 +08:00
|
|
|
TEST(CXXUnresolvedConstructExpr, SourceRange) {
|
|
|
|
RangeVerifier<CXXUnresolvedConstructExpr> Verifier;
|
|
|
|
Verifier.expectRange(3, 10, 3, 12);
|
2013-07-08 22:50:30 +08:00
|
|
|
std::vector<std::string> Args;
|
|
|
|
Args.push_back("-fno-delayed-template-parsing");
|
2013-07-07 14:41:54 +08:00
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"template <typename U>\n"
|
|
|
|
"U foo() {\n"
|
|
|
|
" return U{};\n"
|
|
|
|
"}",
|
2015-09-17 21:30:52 +08:00
|
|
|
cxxUnresolvedConstructExpr(), Args, Lang_CXX11));
|
2013-07-07 14:41:54 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 01:28:56 +08:00
|
|
|
TEST(UsingDecl, SourceRange) {
|
|
|
|
RangeVerifier<UsingDecl> Verifier;
|
|
|
|
Verifier.expectRange(2, 22, 2, 25);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"class B { protected: int i; };\n"
|
|
|
|
"class D : public B { B::i; };",
|
|
|
|
usingDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(UnresolvedUsingValueDecl, SourceRange) {
|
|
|
|
RangeVerifier<UnresolvedUsingValueDecl> Verifier;
|
|
|
|
Verifier.expectRange(3, 3, 3, 6);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"template <typename B>\n"
|
|
|
|
"class D : public B {\n"
|
|
|
|
" B::i;\n"
|
|
|
|
"};",
|
|
|
|
unresolvedUsingValueDecl()));
|
|
|
|
}
|
|
|
|
|
2014-07-17 09:59:34 +08:00
|
|
|
TEST(FriendDecl, FriendNonMemberFunctionLocation) {
|
2014-06-06 12:40:35 +08:00
|
|
|
LocationVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectLocation(2, 13);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"friend void f();\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
2014-07-17 09:59:34 +08:00
|
|
|
TEST(FriendDecl, FriendNonMemberFunctionRange) {
|
2014-06-06 12:40:35 +08:00
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(2, 1, 2, 15);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"friend void f();\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
2014-07-17 09:59:34 +08:00
|
|
|
TEST(FriendDecl, FriendNonMemberFunctionDefinitionLocation) {
|
|
|
|
LocationVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectLocation(2, 12);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"friend int f() { return 0; }\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendNonMemberFunctionDefinitionRange) {
|
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(2, 1, 2, 28);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"friend int f() { return 0; }\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendElaboratedTypeLocation) {
|
2014-06-06 12:40:35 +08:00
|
|
|
LocationVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectLocation(2, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"friend class B;\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
2014-07-17 09:59:34 +08:00
|
|
|
TEST(FriendDecl, FriendElaboratedTypeRange) {
|
2014-06-06 12:40:35 +08:00
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(2, 1, 2, 14);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"friend class B;\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
2014-07-17 09:59:34 +08:00
|
|
|
TEST(FriendDecl, FriendSimpleTypeLocation) {
|
|
|
|
LocationVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectLocation(3, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("class B;\n"
|
|
|
|
"struct A {\n"
|
|
|
|
"friend B;\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl(), Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendSimpleTypeRange) {
|
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(3, 1, 3, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("class B;\n"
|
|
|
|
"struct A {\n"
|
|
|
|
"friend B;\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl(), Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
2014-06-06 12:40:35 +08:00
|
|
|
TEST(FriendDecl, FriendTemplateParameterLocation) {
|
|
|
|
LocationVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectLocation(3, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("template <typename T>\n"
|
|
|
|
"struct A {\n"
|
|
|
|
"friend T;\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl(), Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendTemplateParameterRange) {
|
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(3, 1, 3, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("template <typename T>\n"
|
|
|
|
"struct A {\n"
|
|
|
|
"friend T;\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl(), Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendDecltypeLocation) {
|
|
|
|
LocationVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectLocation(4, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A;\n"
|
|
|
|
"A foo();\n"
|
|
|
|
"struct A {\n"
|
|
|
|
"friend decltype(foo());\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl(), Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendDecltypeRange) {
|
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(4, 1, 4, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A;\n"
|
|
|
|
"A foo();\n"
|
|
|
|
"struct A {\n"
|
|
|
|
"friend decltype(foo());\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl(), Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
2014-07-17 09:59:34 +08:00
|
|
|
TEST(FriendDecl, FriendConstructorDestructorLocation) {
|
|
|
|
const std::string Code = "struct B {\n"
|
|
|
|
"B();\n"
|
|
|
|
"~B();\n"
|
|
|
|
"};\n"
|
|
|
|
"struct A {\n"
|
|
|
|
"friend B::B(), B::~B();\n"
|
|
|
|
"};\n";
|
|
|
|
LocationVerifier<FriendDecl> ConstructorVerifier;
|
|
|
|
ConstructorVerifier.expectLocation(6, 11);
|
|
|
|
EXPECT_TRUE(ConstructorVerifier.match(
|
2015-09-17 21:30:52 +08:00
|
|
|
Code, friendDecl(has(cxxConstructorDecl(ofClass(hasName("B")))))));
|
2014-07-17 09:59:34 +08:00
|
|
|
LocationVerifier<FriendDecl> DestructorVerifier;
|
|
|
|
DestructorVerifier.expectLocation(6, 19);
|
|
|
|
EXPECT_TRUE(DestructorVerifier.match(
|
2015-09-17 21:30:52 +08:00
|
|
|
Code, friendDecl(has(cxxDestructorDecl(ofClass(hasName("B")))))));
|
2014-07-17 09:59:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendConstructorDestructorRange) {
|
|
|
|
const std::string Code = "struct B {\n"
|
|
|
|
"B();\n"
|
|
|
|
"~B();\n"
|
|
|
|
"};\n"
|
|
|
|
"struct A {\n"
|
|
|
|
"friend B::B(), B::~B();\n"
|
|
|
|
"};\n";
|
|
|
|
RangeVerifier<FriendDecl> ConstructorVerifier;
|
|
|
|
ConstructorVerifier.expectRange(6, 1, 6, 13);
|
|
|
|
EXPECT_TRUE(ConstructorVerifier.match(
|
2015-09-17 21:30:52 +08:00
|
|
|
Code, friendDecl(has(cxxConstructorDecl(ofClass(hasName("B")))))));
|
2014-07-17 09:59:34 +08:00
|
|
|
RangeVerifier<FriendDecl> DestructorVerifier;
|
|
|
|
DestructorVerifier.expectRange(6, 1, 6, 22);
|
|
|
|
EXPECT_TRUE(DestructorVerifier.match(
|
2015-09-17 21:30:52 +08:00
|
|
|
Code, friendDecl(has(cxxDestructorDecl(ofClass(hasName("B")))))));
|
2014-07-17 09:59:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendTemplateFunctionLocation) {
|
|
|
|
LocationVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectLocation(3, 13);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"template <typename T>\n"
|
|
|
|
"friend void f();\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendTemplateFunctionRange) {
|
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(2, 1, 3, 15);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"template <typename T>\n"
|
|
|
|
"friend void f();\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendTemplateClassLocation) {
|
|
|
|
LocationVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectLocation(3, 14);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"template <typename T>\n"
|
|
|
|
"friend class B;\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendTemplateClassRange) {
|
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(2, 1, 3, 14);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"template <typename T>\n"
|
|
|
|
"friend class B;\n"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendInlineFunctionLocation) {
|
|
|
|
LocationVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectLocation(2, 19);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"int inline friend f() { return 0; }"
|
|
|
|
"};\n",
|
|
|
|
friendDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FriendDecl, FriendInlineFunctionRange) {
|
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(2, 1, 2, 35);
|
|
|
|
EXPECT_TRUE(Verifier.match("struct A {\n"
|
|
|
|
"int inline friend f() { return 0; }"
|
|
|
|
"};\n",
|
|
|
|
friendDecl(), Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
2013-07-20 02:02:36 +08:00
|
|
|
TEST(FriendDecl, InstantiationSourceRange) {
|
|
|
|
RangeVerifier<FriendDecl> Verifier;
|
|
|
|
Verifier.expectRange(4, 3, 4, 35);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"template <typename T> class S;\n"
|
|
|
|
"template<class T> void operator+(S<T> x);\n"
|
|
|
|
"template<class T> struct S {\n"
|
|
|
|
" friend void operator+<>(S<T> src);\n"
|
|
|
|
"};\n"
|
|
|
|
"void test(S<double> s) { +s; }",
|
2015-09-17 21:30:52 +08:00
|
|
|
friendDecl(hasParent(cxxRecordDecl(isTemplateInstantiation())))));
|
2013-07-20 02:02:36 +08:00
|
|
|
}
|
|
|
|
|
2014-08-01 01:39:50 +08:00
|
|
|
TEST(ObjCMessageExpr, CXXConstructExprRange) {
|
|
|
|
RangeVerifier<CXXConstructExpr> Verifier;
|
|
|
|
Verifier.expectRange(5, 25, 5, 27);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"struct A { int a; };\n"
|
|
|
|
"@interface B {}\n"
|
|
|
|
"+ (void) f1: (A)arg;\n"
|
|
|
|
"@end\n"
|
|
|
|
"void f2() { A a; [B f1: (a)]; }\n",
|
2015-09-17 21:30:52 +08:00
|
|
|
cxxConstructExpr(), Lang_OBJCXX));
|
2014-08-01 01:39:50 +08:00
|
|
|
}
|
|
|
|
|
2016-01-13 05:04:22 +08:00
|
|
|
TEST(FunctionDecl, FunctionDeclWithThrowSpecification) {
|
|
|
|
RangeVerifier<FunctionDecl> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 16);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"void f() throw();\n",
|
|
|
|
functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDecl, FunctionDeclWithNoExceptSpecification) {
|
|
|
|
RangeVerifier<FunctionDecl> Verifier;
|
|
|
|
Verifier.expectRange(1, 1, 1, 24);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"void f() noexcept(false);\n",
|
|
|
|
functionDecl(),
|
|
|
|
Language::Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
2019-12-03 21:21:55 +08:00
|
|
|
class FunctionDeclParametersRangeVerifier : public RangeVerifier<FunctionDecl> {
|
|
|
|
protected:
|
|
|
|
SourceRange getRange(const FunctionDecl &Function) override {
|
|
|
|
return Function.getParametersSourceRange();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclOnlyVariadic) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 8);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(...);\n", functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclVariadic) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 15);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(int a, ...);\n", functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclMacroVariadic) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(2, 8, 1, 18);
|
|
|
|
EXPECT_TRUE(Verifier.match("#define VARIADIC ...\n"
|
|
|
|
"void f(int a, VARIADIC);\n",
|
|
|
|
functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclMacroParams) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 16, 2, 20);
|
|
|
|
EXPECT_TRUE(Verifier.match("#define PARAMS int a, int b\n"
|
|
|
|
"void f(PARAMS, int c);",
|
|
|
|
functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclSingleParameter) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 12);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(int a);\n", functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, MemberFunctionDecl) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(2, 8, 2, 12);
|
|
|
|
EXPECT_TRUE(Verifier.match("class A{\n"
|
|
|
|
"void f(int a);\n"
|
|
|
|
"};",
|
|
|
|
functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, MemberFunctionDeclVariadic) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(2, 8, 2, 15);
|
|
|
|
EXPECT_TRUE(Verifier.match("class A{\n"
|
|
|
|
"void f(int a, ...);\n"
|
|
|
|
"};",
|
|
|
|
functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, StaticFunctionDecl) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(2, 15, 2, 19);
|
|
|
|
EXPECT_TRUE(Verifier.match("class A{\n"
|
|
|
|
"static void f(int a);\n"
|
|
|
|
"};",
|
|
|
|
functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclMultipleParameters) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 28);
|
|
|
|
EXPECT_TRUE(
|
|
|
|
Verifier.match("void f(int a, int b, char *c);\n", functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclWithDefaultValue) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 16);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(int a = 5);\n", functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclWithVolatile) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 22);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(volatile int *i);", functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclWithConstParam) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 19);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(const int *i);", functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclWithConstVolatileParam) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 28);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(const volatile int *i);", functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionDeclParameters, FunctionDeclWithParamAttribute) {
|
|
|
|
FunctionDeclParametersRangeVerifier Verifier;
|
|
|
|
Verifier.expectRange(1, 8, 1, 36);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f(__attribute__((unused)) int a) {}",
|
|
|
|
functionDecl()));
|
|
|
|
}
|
|
|
|
|
2016-01-13 05:04:22 +08:00
|
|
|
TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) {
|
|
|
|
RangeVerifier<FunctionDecl> Verifier;
|
|
|
|
Verifier.expectRange(2, 1, 2, 16);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"class A {\n"
|
|
|
|
"void f() throw();\n"
|
|
|
|
"};\n",
|
|
|
|
functionDecl()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CXXMethodDecl, CXXMethodDeclWithNoExceptSpecification) {
|
|
|
|
RangeVerifier<FunctionDecl> Verifier;
|
|
|
|
Verifier.expectRange(2, 1, 2, 24);
|
|
|
|
EXPECT_TRUE(Verifier.match(
|
|
|
|
"class A {\n"
|
|
|
|
"void f() noexcept(false);\n"
|
|
|
|
"};\n",
|
|
|
|
functionDecl(),
|
|
|
|
Language::Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
2017-01-13 00:11:28 +08:00
|
|
|
class ExceptionSpecRangeVerifier : public RangeVerifier<TypeLoc> {
|
|
|
|
protected:
|
|
|
|
SourceRange getRange(const TypeLoc &Node) override {
|
|
|
|
auto T =
|
|
|
|
Node.getUnqualifiedLoc().castAs<FunctionProtoTypeLoc>();
|
|
|
|
assert(!T.isNull());
|
|
|
|
return T.getExceptionSpecRange();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParmVarExceptionSpecRangeVerifier : public RangeVerifier<ParmVarDecl> {
|
|
|
|
protected:
|
|
|
|
SourceRange getRange(const ParmVarDecl &Node) override {
|
|
|
|
if (const TypeSourceInfo *TSI = Node.getTypeSourceInfo()) {
|
|
|
|
TypeLoc TL = TSI->getTypeLoc();
|
|
|
|
if (TL.getType()->isPointerType()) {
|
|
|
|
TL = TL.getNextTypeLoc().IgnoreParens();
|
|
|
|
if (auto FPTL = TL.getAs<FunctionProtoTypeLoc>()) {
|
|
|
|
return FPTL.getExceptionSpecRange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SourceRange();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(FunctionDecl, ExceptionSpecifications) {
|
|
|
|
ExceptionSpecRangeVerifier Verifier;
|
|
|
|
|
|
|
|
Verifier.expectRange(1, 10, 1, 16);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f() throw();\n", loc(functionType())));
|
|
|
|
|
|
|
|
Verifier.expectRange(1, 10, 1, 34);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f() throw(void(void) throw());\n",
|
|
|
|
loc(functionType())));
|
|
|
|
|
|
|
|
Verifier.expectRange(1, 10, 1, 19);
|
|
|
|
std::vector<std::string> Args;
|
|
|
|
Args.push_back("-fms-extensions");
|
|
|
|
EXPECT_TRUE(Verifier.match("void f() throw(...);\n", loc(functionType()),
|
|
|
|
Args, Language::Lang_CXX));
|
|
|
|
|
|
|
|
Verifier.expectRange(1, 10, 1, 10);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f() noexcept;\n", loc(functionType()),
|
|
|
|
Language::Lang_CXX11));
|
|
|
|
|
|
|
|
Verifier.expectRange(1, 10, 1, 24);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f() noexcept(false);\n", loc(functionType()),
|
|
|
|
Language::Lang_CXX11));
|
|
|
|
|
|
|
|
Verifier.expectRange(1, 10, 1, 32);
|
|
|
|
EXPECT_TRUE(Verifier.match("void f() noexcept(noexcept(1+1));\n",
|
|
|
|
loc(functionType()), Language::Lang_CXX11));
|
|
|
|
|
|
|
|
ParmVarExceptionSpecRangeVerifier Verifier2;
|
|
|
|
Verifier2.expectRange(1, 25, 1, 31);
|
|
|
|
EXPECT_TRUE(Verifier2.match("void g(void (*fp)(void) throw());\n",
|
|
|
|
parmVarDecl(hasType(pointerType(pointee(
|
|
|
|
parenType(innerType(functionType()))))))));
|
|
|
|
|
|
|
|
Verifier2.expectRange(1, 25, 1, 38);
|
|
|
|
EXPECT_TRUE(Verifier2.match("void g(void (*fp)(void) noexcept(true));\n",
|
|
|
|
parmVarDecl(hasType(pointerType(pointee(
|
|
|
|
parenType(innerType(functionType())))))),
|
|
|
|
Language::Lang_CXX11));
|
|
|
|
}
|
|
|
|
|
2012-11-07 01:31:40 +08:00
|
|
|
} // end namespace ast_matchers
|
|
|
|
} // end namespace clang
|