Catch2: clang-tidy complains: initialization with static duration may throw an exception

Created on 28 May 2017  路  3Comments  路  Source: catchorg/Catch2

Using the latest Catch master (and clang-tidy bundled with CLion EAP 2017.2), a simplest example yield clang-tidy warning:

TEST_CASE("whatever") {
    REQUIRE(1 + 2 == 3);
}

clang-tidy lint:

Initialization of 'autoRegistrar1' with static storage duration may throw an exception that cannot be caught.
In progress

Most helpful comment

I've added some judicious /* NOLINT */s to the appropriate places in the source (for this and another one about use of inline assembler on every assertion!). That seems to fix it all.
That's not in the single include yet but I think we'll do a release quite soon to get this fix out.

All 3 comments

This can happen because TEST_CASE's tags are checked for validity and if not, exception is thrown. This is not particularly great when the error happens in statically registered test cases (ie standard usage), but the alternative is to just exit, which is quite a lot worse for users that supply their own main and register test cases dynamically.

There is no proper way to fix it in C++98, but since the next major version drops C++98 support, it is fixed* in the dev-modernize branch.

  • Potential for std::bad_alloc to happen will still be there, there is no good way to get rid of that without serious rework of how test cases are registered

I've added some judicious /* NOLINT */s to the appropriate places in the source (for this and another one about use of inline assembler on every assertion!). That seems to fix it all.
That's not in the single include yet but I think we'll do a release quite soon to get this fix out.

@philsquared Thanks! Hopefully those pesky warnings in CLion will go away.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eloff picture eloff  路  7Comments

Viatorus picture Viatorus  路  3Comments

pwinston picture pwinston  路  5Comments

Aivean picture Aivean  路  6Comments

qneverless picture qneverless  路  6Comments