[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:
Congcong Cai
2024-11-22 05:01:49 +08:00
committed by GitHub
parent b62557aaeb
commit fd2e0483de
3 changed files with 24 additions and 0 deletions

View File

@@ -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;

View File

@@ -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.

View File

@@ -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