]> granicus.if.org Git - clang/commitdiff
[ASTImporter] Add test for C++'s try/catch statements.
authorRaphael Isemann <teemperor@gmail.com>
Mon, 20 Aug 2018 22:13:24 +0000 (22:13 +0000)
committerRaphael Isemann <teemperor@gmail.com>
Mon, 20 Aug 2018 22:13:24 +0000 (22:13 +0000)
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

test/Import/cxx-try-catch/Inputs/F.cpp [new file with mode: 0644]
test/Import/cxx-try-catch/test.cpp [new file with mode: 0644]
tools/clang-import-test/clang-import-test.cpp

diff --git a/test/Import/cxx-try-catch/Inputs/F.cpp b/test/Import/cxx-try-catch/Inputs/F.cpp
new file mode 100644 (file)
index 0000000..4e06f35
--- /dev/null
@@ -0,0 +1,18 @@
+void f() {
+  try {
+  } catch (...) {
+  }
+
+  try {
+  } catch (int) {
+  }
+
+  try {
+  } catch (int varname) {
+  }
+
+  try {
+  } catch (int varname1) {
+  } catch (long varname2) {
+  }
+}
diff --git a/test/Import/cxx-try-catch/test.cpp b/test/Import/cxx-try-catch/test.cpp
new file mode 100644 (file)
index 0000000..079e35b
--- /dev/null
@@ -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();
+}
index ff14f62574ef82114f44a3a9fef2fda5445c42c7..f64f0f8042de3053d50ea13990c77ab936b81192 100644 (file)
@@ -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);