summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2015-12-01 14:05:39 +0000
committerAaron Ballman <aaron@aaronballman.com>2015-12-01 14:05:39 +0000
commit43aef4cb9bf7053a7f814fee124b2bbde9850578 (patch)
tree5a22ecf8cdd861b1ee47c986c8a2cffd31a01234 /clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp
parenta0a5039d2e520fd42646cb305ed8b696acb41e63 (diff)
downloadbcm5719-llvm-43aef4cb9bf7053a7f814fee124b2bbde9850578.tar.gz
bcm5719-llvm-43aef4cb9bf7053a7f814fee124b2bbde9850578.zip
Add a new checker, cert-err58-cpp, that checks for static or thread_local objects that use a throwing constructor.
This check corresponds to the CERT secure coding rule: https://www.securecoding.cert.org/confluence/display/cplusplus/ERR58-CPP.+Constructors+of+objects+with+static+or+thread+storage+duration+must+not+throw+exceptions llvm-svn: 254415
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp b/clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp
new file mode 100644
index 00000000000..4e4c622c7ca
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp
@@ -0,0 +1,52 @@
+// RUN: %check_clang_tidy %s cert-err58-cpp %t
+
+struct S {
+ S() noexcept(false);
+};
+
+struct T {
+ T() noexcept;
+};
+
+struct U {
+ U() {}
+};
+
+struct V {
+ explicit V(const char *) {} // Can throw
+};
+
+
+S s;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 's' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
+// CHECK-MESSAGES: 4:3: note: possibly throwing constructor declared here
+T t; // ok
+U u;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'u' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 12:3: note: possibly throwing constructor declared here
+V v("v");
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+
+void f(S s1, T t1, U u1, V v1) { // ok, ok, ok, ok
+ S s2; // ok
+ T t2; // ok
+ U u2; // ok
+ V v2("v"); // ok
+
+ thread_local S s3;
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: construction of 's3' with thread_local storage duration may throw an exception that cannot be caught
+ thread_local T t3; // ok
+ thread_local U u3;
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
+ thread_local V v3("v");
+ // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+
+ static S s4;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 's4' with static storage duration may throw an exception that cannot be caught
+ static T t4; // ok
+ static U u4;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'u4' with static storage duration may throw an exception that cannot be caught
+ static V v4("v");
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'v4' with static storage duration may throw an exception that cannot be caught
+}
OpenPOWER on IntegriCloud