Skip to content

Commit f18becd

Browse files
committed
Add some more tests and comments
1 parent 47c2c2e commit f18becd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,14 @@ ExceptionAnalyzer::throwsException(const Stmt *St,
591591
Results.merge(Excs);
592592
}
593593
} else {
594+
// Check whether any of this node's subexpressions throws.
594595
for (const Stmt *Child : St->children()) {
595596
ExceptionInfo Excs = throwsException(Child, Caught, CallStack);
596597
Results.merge(Excs);
597598
}
598599

600+
// If this node is a call to a function or constructor, also check
601+
// whether the call itself throws.
599602
if (const auto *Call = dyn_cast<CallExpr>(St)) {
600603
if (const FunctionDecl *Func = Call->getDirectCallee()) {
601604
ExceptionInfo Excs =

clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,13 +964,27 @@ void throw_in_function_arg() noexcept {
964964
}
965965
// CHECK-MESSAGES: :[[@LINE-2]]:17: note: frame #0: unhandled exception of type 'int' may be thrown in function 'throw_in_function_arg' here
966966

967+
int g(int, int, int);
968+
void throw_in_last_function_arg() noexcept {
969+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_in_last_function_arg' which should not throw exceptions
970+
g(42, 67, false ? 0 : throw 1);
971+
}
972+
// CHECK-MESSAGES: :[[@LINE-2]]:25: note: frame #0: unhandled exception of type 'int' may be thrown in function 'throw_in_last_function_arg' here
973+
967974
void indirect_throw_in_function_arg() noexcept {
968975
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_throw_in_function_arg' which should not throw exceptions
969976
f(thrower());
970977
}
971-
// CHECK-MESSAGES: :[[@LINE-19]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'thrower' here
978+
// CHECK-MESSAGES: :[[@LINE-26]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'thrower' here
972979
// CHECK-MESSAGES: :[[@LINE-3]]:5: note: frame #1: function 'indirect_throw_in_function_arg' calls function 'thrower' here
973980

981+
void indirect_throw_from_lambda_in_function_arg() noexcept {
982+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_throw_from_lambda_in_function_arg' which should not throw exceptions
983+
f([] { throw 1; return 0; }());
984+
}
985+
// CHECK-MESSAGES: :[[@LINE-2]]:10: note: frame #0: unhandled exception of type 'int' may be thrown in function 'operator()' here
986+
// CHECK-MESSAGES: :[[@LINE-3]]:30: note: frame #1: function 'indirect_throw_from_lambda_in_function_arg' calls function 'operator()' here
987+
974988
struct S {
975989
S(int) noexcept {}
976990
};
@@ -985,7 +999,7 @@ void indirect_throw_in_constructor_arg() noexcept {
985999
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_throw_in_constructor_arg' which should not throw exceptions
9861000
S s = thrower();
9871001
}
988-
// CHECK-MESSAGES: :[[@LINE-36]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'thrower' here
1002+
// CHECK-MESSAGES: :[[@LINE-50]]:3: note: frame #0: unhandled exception of type 'int' may be thrown in function 'thrower' here
9891003
// CHECK-MESSAGES: :[[@LINE-3]]:9: note: frame #1: function 'indirect_throw_in_constructor_arg' calls function 'thrower' here
9901004

9911005
void weird_throw_in_call_subexpression() noexcept {

0 commit comments

Comments
 (0)