[clang-tools-extra] r282409 - Silence a false positive with the cert-err58-cpp check; now allows objects with static or thread storage duration at function block scope.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 26 08:00:46 PDT 2016
Author: aaronballman
Date: Mon Sep 26 10:00:45 2016
New Revision: 282409
URL: http://llvm.org/viewvc/llvm-project?rev=282409&view=rev
Log:
Silence a false positive with the cert-err58-cpp check; now allows objects with static or thread storage duration at function block scope.
Patch by Malcolm Parsons
Modified:
clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
Modified: clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp?rev=282409&r1=282408&r2=282409&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp Mon Sep 26 10:00:45 2016
@@ -26,9 +26,9 @@ void StaticObjectExceptionCheck::registe
// with a constructor that can throw.
Finder->addMatcher(
varDecl(anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
+ unless(hasAncestor(functionDecl())),
hasInitializer(cxxConstructExpr(hasDeclaration(
- cxxConstructorDecl(unless(isNoThrow()))
- .bind("ctor")))))
+ cxxConstructorDecl(unless(isNoThrow())).bind("ctor")))))
.bind("var"),
this);
}
Modified: clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp?rev=282409&r1=282408&r2=282409&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp Mon Sep 26 10:00:45 2016
@@ -28,25 +28,89 @@ 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
+thread_local S s3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: 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]]:16: 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]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+
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 S s3; // ok
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
+ thread_local U u3; // ok
+ thread_local V v3("v"); // ok
- 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 S s4; // ok
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
+ static U u4; // ok
+ static V v4("v"); // ok
}
+
+namespace {
+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
+
+thread_local S s3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: 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]]:16: 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]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+};
+
+class Statics {
+ static S s;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: 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
+ static T t; // ok
+ static U u;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: 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
+ static V v;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: 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 s, T t, U u, V v) {
+ S s2; // ok
+ T t2; // ok
+ U u2; // ok
+ V v2("v"); // ok
+
+ thread_local S s3; // ok
+ thread_local T t3; // ok
+ thread_local U u3; // ok
+ thread_local V v3("v"); // ok
+
+ static S s4; // ok
+ static T t4; // ok
+ static U u4; // ok
+ static V v4("v"); // ok
+ }
+};
+
+S Statics::s;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: 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 Statics::t;
+U Statics::u;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: 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 Statics::v("v");
+// CHECK-MESSAGES: :[[@LINE-1]]:12: 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
More information about the cfe-commits
mailing list