Skip to content

Commit 778269d

Browse files
committedOct 16, 2016
[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 llvm-svn: 284332
1 parent ebb006e commit 778269d

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed
 

‎clang-tools-extra/clang-tidy/cert/StaticObjectExceptionCheck.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ void StaticObjectExceptionCheck::registerMatchers(MatchFinder *Finder) {
2727
Finder->addMatcher(
2828
varDecl(anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
2929
unless(hasAncestor(functionDecl())),
30-
hasInitializer(cxxConstructExpr(hasDeclaration(
31-
cxxConstructorDecl(unless(isNoThrow())).bind("ctor")))))
30+
hasInitializer(ignoringImplicit(cxxConstructExpr(hasDeclaration(
31+
cxxConstructorDecl(unless(isNoThrow())).bind("ctor"))))))
3232
.bind("var"),
3333
this);
3434
}

‎clang-tools-extra/test/clang-tidy/cert-static-object-exception.cpp

+32-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ struct V {
1616
explicit V(const char *) {} // Can throw
1717
};
1818

19+
struct Cleanup
20+
{
21+
~Cleanup() {}
22+
};
23+
24+
struct W {
25+
W(Cleanup c = {}) noexcept(false);
26+
};
27+
1928

2029
S s;
2130
// 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;
2736
V v("v");
2837
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
2938
// CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
39+
W w;
40+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
41+
// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
3042

3143
thread_local S s3;
3244
// 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;
3547
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
3648
thread_local V v3("v");
3749
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
50+
thread_local W w3;
51+
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with thread_local storage duration may throw an exception that cannot be caught
3852

39-
void f(S s1, T t1, U u1, V v1) { // ok, ok, ok, ok
53+
void f(S s1, T t1, U u1, V v1, W w1) { // ok, ok, ok, ok, ok
4054
S s2; // ok
4155
T t2; // ok
4256
U u2; // ok
4357
V v2("v"); // ok
58+
W w2; // ok
4459

4560
thread_local S s3; // ok
4661
thread_local T t3; // ok
4762
thread_local U u3; // ok
4863
thread_local V v3("v"); // ok
64+
thread_local W w3; // ok
4965

5066
static S s4; // ok
5167
static T t4; // ok
5268
static U u4; // ok
5369
static V v4("v"); // ok
70+
static W w4; // ok
5471
}
5572

5673
namespace {
@@ -64,6 +81,9 @@ U u;
6481
V v("v");
6582
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
6683
// CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
84+
W w;
85+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
86+
// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
6787

6888
thread_local S s3;
6989
// 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;
7292
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
7393
thread_local V v3("v");
7494
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
95+
thread_local W w3;
96+
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with thread_local storage duration may throw an exception that cannot be caught
7597
};
7698

7799
class Statics {
@@ -85,22 +107,28 @@ class Statics {
85107
static V v;
86108
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
87109
// CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
110+
static W w;
111+
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
112+
// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
88113

89114
void f(S s, T t, U u, V v) {
90115
S s2; // ok
91116
T t2; // ok
92117
U u2; // ok
93118
V v2("v"); // ok
119+
W w2; // ok
94120

95121
thread_local S s3; // ok
96122
thread_local T t3; // ok
97123
thread_local U u3; // ok
98124
thread_local V v3("v"); // ok
125+
thread_local W w3; // ok
99126

100127
static S s4; // ok
101128
static T t4; // ok
102129
static U u4; // ok
103130
static V v4("v"); // ok
131+
static W w4; // ok
104132
}
105133
};
106134

@@ -114,3 +142,6 @@ U Statics::u;
114142
V Statics::v("v");
115143
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
116144
// CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
145+
W Statics::w;
146+
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
147+
// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here

0 commit comments

Comments
 (0)
Please sign in to comment.