[clang-tools-extra] r284332 - [clang-tidy] Use ignoreImplicit in cert-err58-cpp check
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 16 02:47:10 PDT 2016
Author: malcolm.parsons
Date: Sun Oct 16 04:47:10 2016
New Revision: 284332
URL: http://llvm.org/viewvc/llvm-project?rev=284332&view=rev
Log:
[clang-tidy] Use ignoreImplicit in cert-err58-cpp check
Summary:
Fix a false negative in cert-err58-cpp check when calling a constructor
creates objects that require cleanup.
Reviewers: aaron.ballman
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D25642
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=284332&r1=284331&r2=284332&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp Sun Oct 16 04:47:10 2016
@@ -27,8 +27,8 @@ void StaticObjectExceptionCheck::registe
Finder->addMatcher(
varDecl(anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
unless(hasAncestor(functionDecl())),
- hasInitializer(cxxConstructExpr(hasDeclaration(
- cxxConstructorDecl(unless(isNoThrow())).bind("ctor")))))
+ hasInitializer(ignoringImplicit(cxxConstructExpr(hasDeclaration(
+ 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=284332&r1=284331&r2=284332&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 Sun Oct 16 04:47:10 2016
@@ -16,6 +16,15 @@ struct V {
explicit V(const char *) {} // Can throw
};
+struct Cleanup
+{
+ ~Cleanup() {}
+};
+
+struct W {
+ W(Cleanup c = {}) noexcept(false);
+};
+
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]
@@ -27,6 +36,9 @@ U u;
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
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: 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
@@ -35,22 +47,27 @@ 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
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' 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
+void f(S s1, T t1, U u1, V v1, W w1) { // ok, ok, ok, ok, ok
S s2; // ok
T t2; // ok
U u2; // ok
V v2("v"); // ok
+ W w2; // ok
thread_local S s3; // ok
thread_local T t3; // ok
thread_local U u3; // ok
thread_local V v3("v"); // ok
+ thread_local W w3; // ok
static S s4; // ok
static T t4; // ok
static U u4; // ok
static V v4("v"); // ok
+ static W w4; // ok
}
namespace {
@@ -64,6 +81,9 @@ U u;
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
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: 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
@@ -72,6 +92,8 @@ 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
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with thread_local storage duration may throw an exception that cannot be caught
};
class Statics {
@@ -85,22 +107,28 @@ class Statics {
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
+ static W w;
+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+ // CHECK-MESSAGES: 25:3: 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
+ W w2; // ok
thread_local S s3; // ok
thread_local T t3; // ok
thread_local U u3; // ok
thread_local V v3("v"); // ok
+ thread_local W w3; // ok
static S s4; // ok
static T t4; // ok
static U u4; // ok
static V v4("v"); // ok
+ static W w4; // ok
}
};
@@ -114,3 +142,6 @@ U Statics::u;
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
+W Statics::w;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
More information about the cfe-commits
mailing list