================
@@ -146,24 +146,35 @@ void ExceptionEscapeCheck::check(const
MatchFinder::MatchResult &Result) {
"%0 which should not throw exceptions")
<< MatchedDecl;
- if (Info.getExceptions().empty())
- return;
-
- const auto &[ThrowType, ThrowInfo] = *Info.getExceptions().begin();
+ const utils::ExceptionAnalyzer::ExceptionInfo::Throwables &Exceptions =
+ Info.getExceptions();
+ const utils::ExceptionAnalyzer::ExceptionInfo::ThrowInfo *TI = nullptr;
+ if (!Exceptions.empty())
+ TI = &Exceptions.begin()->second;
+ else if (Info.containsUnknownElements())
+ TI = &Info.getUnknownThrowInfo();
- if (ThrowInfo.Loc.isInvalid())
+ if (!TI || TI->Loc.isInvalid())
return;
- const utils::ExceptionAnalyzer::CallStack &Stack = ThrowInfo.Stack;
- diag(ThrowInfo.Loc,
- "frame #0: unhandled exception of type %0 may be thrown in function %1 "
- "here",
- DiagnosticIDs::Note)
- << QualType(ThrowType, 0U) << Stack.back().first;
+ if (!Exceptions.empty()) {
+ const auto &[ThrowType, ThrowInfo] = *Exceptions.begin();
+ diag(ThrowInfo.Loc,
+ "frame #0: unhandled exception of type %0 may be thrown in function "
+ "%1 here",
+ DiagnosticIDs::Note)
+ << QualType(ThrowType, 0U) << ThrowInfo.Stack.back().first;
----------------
zeyi2 wrote:
I tried to change this to just `ThrowType`, unfortunately there is a
compilation failure:
```
/home/mitchell/Documents/projects/llvm-project/clang/include/clang/Basic/Diagnostic.h:1319:8:
error: invalid operands to binary expression ('const StreamingDiagnostic' and
'const clang::Type *const')
1319 | DB << V;
| ~~ ^ ~
/home/mitchell/Documents/projects/llvm-project/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp:166:9:
note: in instantiation of function template specialization
'clang::DiagnosticBuilder::operator<<<const clang::Type *>' requested here
166 | << ThrowType << ThrowInfo.Stack.back().first;
| ^
```
Seems that `StreamingDiagnostic` has an overloaded `operator<<` specifically
for `QualType`, but not for a raw `const clang::Type *`.
So I'd like to stick with the original implementation. WDYT?
https://github.com/llvm/llvm-project/pull/187971
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits