[clang-tidy] ignore consteval function in ExceptionAnalyzer (#116643)
`ExceptionAnalyzer` can ignore `consteval` function even if it will throw exception. `consteval` function must produce compile-time constant. But throw statement cannot appear in constant evaluation. Fixed: #104457.
This commit is contained in:
@@ -320,6 +320,12 @@ bool isQualificationConvertiblePointer(QualType From, QualType To,
|
||||
} // namespace
|
||||
|
||||
static bool canThrow(const FunctionDecl *Func) {
|
||||
// consteval specifies that every call to the function must produce a
|
||||
// compile-time constant, which cannot evaluate a throw expression without
|
||||
// producing a compilation error.
|
||||
if (Func->isConsteval())
|
||||
return false;
|
||||
|
||||
const auto *FunProto = Func->getType()->getAs<FunctionProtoType>();
|
||||
if (!FunProto)
|
||||
return true;
|
||||
|
||||
@@ -162,6 +162,10 @@ Changes in existing checks
|
||||
<clang-tidy/checks/bugprone/dangling-handle>` check to treat `std::span` as a
|
||||
handle class.
|
||||
|
||||
- Improved :doc:`bugprone-exception-escape
|
||||
<clang-tidy/checks/bugprone/exception-escape>` by fixing false positives
|
||||
when a consteval function with throw statements.
|
||||
|
||||
- Improved :doc:`bugprone-forwarding-reference-overload
|
||||
<clang-tidy/checks/bugprone/forwarding-reference-overload>` check by fixing
|
||||
a crash when determining if an ``enable_if[_t]`` was found.
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// RUN: %check_clang_tidy -std=c++20 %s bugprone-exception-escape %t -- \
|
||||
// RUN: -- -fexceptions -Wno-everything
|
||||
|
||||
namespace GH104457 {
|
||||
|
||||
consteval int consteval_fn(int a) {
|
||||
if (a == 0)
|
||||
throw 1;
|
||||
return a;
|
||||
}
|
||||
|
||||
int test() noexcept { return consteval_fn(1); }
|
||||
|
||||
} // namespace GH104457
|
||||
Reference in New Issue
Block a user