llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

`bugprone-exception-escape` should ignore `consteval` #104457

Open chfast opened 3 months ago

chfast commented 3 months ago

The clang-tidy check bugprone-exception-escape should ignore the consteval functions. These are only executed at compile time and if they throw an exception the compilation fails.

consteval int consteval_fn(int a)
{
    if (a == 0)
        throw 1;
    return a;
}

int test() noexcept
{
    return consteval_fn(1);
}

https://godbolt.org/z/G9WGK3d56

To trigger the warning you can call a consteval function with throw statement. You can also mark such consteval function with noexcept. I'm not sure how to interpret the intention in the second case so may this is not worth fixing.

llvmbot commented 3 months ago

@llvm/issue-subscribers-clang-tidy

Author: Paweł Bylica (chfast)

The clang-tidy check `bugprone-exception-escape` should ignore the `consteval` functions. These are only executed at compile time and if they throw an exception the compilation fails. ```cpp consteval int consteval_fn(int a) { if (a == 0) throw 1; return a; } int test() noexcept { return consteval_fn(1); } ``` https://godbolt.org/z/G9WGK3d56 To trigger the warning you can call a `consteval` function with `throw` statement. You can also mark such `consteval` function with `noexcept`. I'm not sure how to interpret the intention in the second case so may this is not worth fixing.