<feed xmlns='http://www.w3.org/2005/Atom'>
<title>catch3/src/catch2/internal/catch_test_macro_impl.hpp, branch v3.0.0-preview4</title>
<subtitle>Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.</subtitle>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/'/>
<entry>
<title>Disable false positive from clang-tidy</title>
<updated>2021-10-21T20:45:19+00:00</updated>
<author>
<name>Anders Schau Knatten</name>
</author>
<published>2021-09-29T13:34:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=22750cde0e0d2c02ab447e2500422f2711356053'/>
<id>22750cde0e0d2c02ab447e2500422f2711356053</id>
<content type='text'>
Clang-tidy is smart enough to understand that the conditional is never
updated in the loop body. It will let you get away with it if it can
prove that the conditional is always false, but that is not always
possible.

Here is an example where it's not able to prove it, and thus gives a
false positive. This is a minimal reproduction of an actual case I hit
in production, where `function` is picking the function based on some
`constexpr` logic related to which type argument is currently being
tested.

```
int f();

TEMPLATE_TEST_CASE("reproduction", "", int) {
    const auto function = []() {
        return f;
    }();
    const int error = function();
    REQUIRE(error == 0); // clang-tidy complains: bugprone-infinite-loop
}
```

I did not choose to add this test to the test suite, since we're not
running `clang-tidy` in CI afaik. To run it manually, simply add the
snippet above somewhere and run clang-tidy with
`--checks=bugprone-infinite-loop`. Or see an example at
https://godbolt.org/z/4v8b8WexP.

The reason we get the infinite loop warning in the first place is the
conditional at the end of this `do`-loop. Ideally, this conditional
would just be `while(false)`, but the actual content of the
`REQUIRE`-statement has been included here too in order to not loose
warnings from signed/unsigned comparisons. In short, if you do
`REQUIRE(i &lt; j)`, where `i` is a negative signed integer and `j` is an
unsigned integer, you're supposed to get a warning from
`-Wsign-compare`. Due to the decomposition in Catch2, you lose this
warning, which is why the content of the `REQUIRE` statement has been
added to the conditional to force the compiler to evaluate the actual
comparison as well.

This was discussed on Discord today, and an alternative approach (which
I don't have time to implement) would be to in the decomposition replace
the comparison operators with `cmp_less` and friends. These are C++20
though, and would have to be implemented manually. I am also not sure
it's a good idea to "magically" change the semantics of `&lt;` when it's
used inside a `REQUIRE` macro.

Another alternative approach would be to trigger this warning in a
different way, by including the content of the `REQUIRE` macro in a
different way which doesn't affect the for loop. But I don't have enough
of an overview here to know where would be a good place and how to test
that I didn't break anything.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Clang-tidy is smart enough to understand that the conditional is never
updated in the loop body. It will let you get away with it if it can
prove that the conditional is always false, but that is not always
possible.

Here is an example where it's not able to prove it, and thus gives a
false positive. This is a minimal reproduction of an actual case I hit
in production, where `function` is picking the function based on some
`constexpr` logic related to which type argument is currently being
tested.

```
int f();

TEMPLATE_TEST_CASE("reproduction", "", int) {
    const auto function = []() {
        return f;
    }();
    const int error = function();
    REQUIRE(error == 0); // clang-tidy complains: bugprone-infinite-loop
}
```

I did not choose to add this test to the test suite, since we're not
running `clang-tidy` in CI afaik. To run it manually, simply add the
snippet above somewhere and run clang-tidy with
`--checks=bugprone-infinite-loop`. Or see an example at
https://godbolt.org/z/4v8b8WexP.

The reason we get the infinite loop warning in the first place is the
conditional at the end of this `do`-loop. Ideally, this conditional
would just be `while(false)`, but the actual content of the
`REQUIRE`-statement has been included here too in order to not loose
warnings from signed/unsigned comparisons. In short, if you do
`REQUIRE(i &lt; j)`, where `i` is a negative signed integer and `j` is an
unsigned integer, you're supposed to get a warning from
`-Wsign-compare`. Due to the decomposition in Catch2, you lose this
warning, which is why the content of the `REQUIRE` statement has been
added to the conditional to force the compiler to evaluate the actual
comparison as well.

This was discussed on Discord today, and an alternative approach (which
I don't have time to implement) would be to in the decomposition replace
the comparison operators with `cmp_less` and friends. These are C++20
though, and would have to be implemented manually. I am also not sure
it's a good idea to "magically" change the semantics of `&lt;` when it's
used inside a `REQUIRE` macro.

Another alternative approach would be to trigger this warning in a
different way, by including the content of the `REQUIRE` macro in a
different way which doesn't affect the for loop. But I don't have enough
of an overview here to know where would be a good place and how to test
that I didn't break anything.
</pre>
</div>
</content>
</entry>
<entry>
<title>Bring back useful comment</title>
<updated>2021-09-29T16:19:31+00:00</updated>
<author>
<name>Anders Schau Knatten</name>
</author>
<published>2021-09-29T11:54:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=eb452e9b356de09bdb96273c035c40a8f4cb2ad3'/>
<id>eb452e9b356de09bdb96273c035c40a8f4cb2ad3</id>
<content type='text'>
In b7b346c3e56030 this conditional was simplified to just
`while( false)` rather than the current one. Then in 3a33315ff8e04, that
change was reverted. I found it hard to understand this
complicated conditional, but after some digging in history I found this
comment which used to be here. It was removed in b7b346c3e56030, but not
restored together with the revert in 3a33315ff8e04. Let's revive it.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In b7b346c3e56030 this conditional was simplified to just
`while( false)` rather than the current one. Then in 3a33315ff8e04, that
change was reverted. I found it hard to understand this
complicated conditional, but after some digging in history I found this
comment which used to be here. It was removed in b7b346c3e56030, but not
restored together with the revert in 3a33315ff8e04. Let's revive it.
</pre>
</div>
</content>
</entry>
<entry>
<title>Split out INTERNAL_CATCH_UNIQUE_NAME into its own header</title>
<updated>2021-02-24T22:14:18+00:00</updated>
<author>
<name>Martin Hořeňovský</name>
</author>
<published>2021-02-24T22:13:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=551946c45bb27b78c85971d32e2a8bccbfa0d3f8'/>
<id>551946c45bb27b78c85971d32e2a8bccbfa0d3f8</id>
<content type='text'>
Also small cleanup of includes of related headers.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Also small cleanup of includes of related headers.
</pre>
</div>
</content>
</entry>
<entry>
<title>Silence -Wuseless-cast warning with GCC10</title>
<updated>2020-11-02T15:01:17+00:00</updated>
<author>
<name>Morwenn</name>
</author>
<published>2020-10-29T14:04:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=dd5652933ae181226eac0177e1b6ab0d988bdec6'/>
<id>dd5652933ae181226eac0177e1b6ab0d988bdec6</id>
<content type='text'>
With GCC 10, the `static_cast&lt;bool&gt;` triggers the -Wuseless-cast warning. This commit changes the cast into `static_cast&lt;const bool&amp;&gt;`: it achieves the same thing but doesn't trigger the warning thanks to the "gratuitous" type conversion to `const bool&amp;`. As per references rules, `const bool&amp;` should bind to anything, be it `const` or not, an rvalue or an lvalue, so I doubt that this change is breaking anything.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
With GCC 10, the `static_cast&lt;bool&gt;` triggers the -Wuseless-cast warning. This commit changes the cast into `static_cast&lt;const bool&amp;&gt;`: it achieves the same thing but doesn't trigger the warning thanks to the "gratuitous" type conversion to `const bool&amp;`. As per references rules, `const bool&amp;` should bind to anything, be it `const` or not, an rvalue or an lvalue, so I doubt that this change is breaking anything.</pre>
</div>
</content>
</entry>
<entry>
<title>Add standardized copyright notice + SPDX identifier to source files</title>
<updated>2020-08-30T13:43:45+00:00</updated>
<author>
<name>Martin Hořeňovský</name>
</author>
<published>2020-08-30T13:43:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=90aeffb97d6942d16f75a56b11e10fc0b010995a'/>
<id>90aeffb97d6942d16f75a56b11e10fc0b010995a</id>
<content type='text'>
This should also be done for test files, but that has lower priority.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This should also be done for test files, but that has lower priority.
</pre>
</div>
</content>
</entry>
<entry>
<title>Standardize include guard patterns to FILE_NAME_EXTENSION_INCLUDED</title>
<updated>2020-08-30T12:09:27+00:00</updated>
<author>
<name>Martin Hořeňovský</name>
</author>
<published>2020-08-29T18:48:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=a822cb9717b64b3b17047fe1ab4dc727c2ff39c4'/>
<id>a822cb9717b64b3b17047fe1ab4dc727c2ff39c4</id>
<content type='text'>
This commit also strips the old copyright comment header in touched
files, as those will also be replaced with a more standardized and
machine-friendly version.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This commit also strips the old copyright comment header in touched
files, as those will also be replaced with a more standardized and
machine-friendly version.
</pre>
</div>
</content>
</entry>
<entry>
<title>Rename catch_assertionhandler -&gt; catch_assertion_handler</title>
<updated>2020-05-10T18:20:56+00:00</updated>
<author>
<name>Martin Hořeňovský</name>
</author>
<published>2020-05-10T16:24:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=d5e08a4beb09a8c1affb6d145b1a7b2805a9bb2a'/>
<id>d5e08a4beb09a8c1affb6d145b1a7b2805a9bb2a</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Move StringRef header to internals</title>
<updated>2020-05-10T08:09:01+00:00</updated>
<author>
<name>Martin Hořeňovský</name>
</author>
<published>2020-05-10T08:09:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=9e498278be92ff209687a09b989f27d51aab7809'/>
<id>9e498278be92ff209687a09b989f27d51aab7809</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix compilation error when lambdas are used in assertions</title>
<updated>2020-05-01T07:24:26+00:00</updated>
<author>
<name>Martin Hořeňovský</name>
</author>
<published>2020-03-19T12:32:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=5198fd3c9a4cd943786020abbdfc15dc5789be6f'/>
<id>5198fd3c9a4cd943786020abbdfc15dc5789be6f</id>
<content type='text'>
This is a partial revert of b7b346c3e5603.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is a partial revert of b7b346c3e5603.
</pre>
</div>
</content>
</entry>
<entry>
<title>Make warnings in assertions fire for GCC/Clang again</title>
<updated>2020-04-29T19:27:57+00:00</updated>
<author>
<name>Martin Hořeňovský</name>
</author>
<published>2020-03-18T19:59:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.progmasoft.com/catch3/commit/?id=60cfaa38fbd7a9a0fa2366e70367aef3696efc73'/>
<id>60cfaa38fbd7a9a0fa2366e70367aef3696efc73</id>
<content type='text'>
The old code caused warnings to fire under MSVC, and Clang &lt;3.8.
I could not find a GCC version where it worked, but I assume that it
did at some point.

This new code causes all of MSVC, GCC, Clang, in current versions,
to emit signed/unsigned comparison warning in test like this:

```cpp
TEST_CASE() {
    int32_t i = -1;
    uint32_t j = 1;
    REQUIRE(i != j);
}
```

Where previously only MSVC would emit the warning.

Fixes #1880
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The old code caused warnings to fire under MSVC, and Clang &lt;3.8.
I could not find a GCC version where it worked, but I assume that it
did at some point.

This new code causes all of MSVC, GCC, Clang, in current versions,
to emit signed/unsigned comparison warning in test like this:

```cpp
TEST_CASE() {
    int32_t i = -1;
    uint32_t j = 1;
    REQUIRE(i != j);
}
```

Where previously only MSVC would emit the warning.

Fixes #1880
</pre>
</div>
</content>
</entry>
</feed>
