Skip to content

Commit

Permalink
[ASTImporter] Add test for C++'s try/catch statements.
Browse files Browse the repository at this point in the history
Summary: Also enable exceptions in clang-import-test so that we can parse the test files.

Reviewers: a.sidorin, a_sidorin

Reviewed By: a_sidorin

Subscribers: a_sidorin, martong, cfe-commits

Differential Revision: https://reviews.llvm.org/D50978

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340220 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Teemperor committed Aug 20, 2018
1 parent 98caebc commit e205163
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/Import/cxx-try-catch/Inputs/F.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
void f() {
try {
} catch (...) {
}

try {
} catch (int) {
}

try {
} catch (int varname) {
}

try {
} catch (int varname1) {
} catch (long varname2) {
}
}
39 changes: 39 additions & 0 deletions test/Import/cxx-try-catch/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | FileCheck %s

// CHECK: CXXTryStmt
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXCatchStmt
// CHECK-NEXT: <<NULL>>
// CHECK-NEXT: CompoundStmt

// CHECK: CXXTryStmt
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXCatchStmt
// CHECK-NEXT: VarDecl
// CHECK-SAME: 'int'
// CHECK-NEXT: CompoundStmt

// CHECK: CXXTryStmt
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXCatchStmt
// CHECK-NEXT: VarDecl
// CHECK-SAME: varname
// CHECK-SAME: 'int'
// CHECK-NEXT: CompoundStmt

// CHECK: CXXTryStmt
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXCatchStmt
// CHECK-NEXT: VarDecl
// CHECK-SAME: varname1
// CHECK-SAME: 'int'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: CXXCatchStmt
// CHECK-NEXT: VarDecl
// CHECK-SAME: varname2
// CHECK-SAME: 'long'
// CHECK-NEXT: CompoundStmt

void expr() {
f();
}
2 changes: 2 additions & 0 deletions tools/clang-import-test/clang-import-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance() {
Inv->getLangOpts()->ThreadsafeStatics = false;
Inv->getLangOpts()->AccessControl = false;
Inv->getLangOpts()->DollarIdents = true;
Inv->getLangOpts()->Exceptions = true;
Inv->getLangOpts()->CXXExceptions = true;
// Needed for testing dynamic_cast.
Inv->getLangOpts()->RTTI = true;
Inv->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo);
Expand Down

0 comments on commit e205163

Please sign in to comment.