Skip to content

[clang-tidy] ignore consteval function in ExceptionAnalyzer #116643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading