"Use of the comma-operator in a tested expression causes the left argument to be ignored when it has no side-effects"
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
I get compiler warnings that among other things match the title above.
Furthermore, I also get a "( && ) is always zero. is never evaluated and might have side effects.
**Expected behavior**
Maybe it's naive of me, but I expected no warnings.
**Reproduction steps**
Steps to reproduce the bug.
Visual Studio 2019 with the language standard "ISO C++17 Standard (std:c++17)".
Definition of `equals_epsilon`:
```cpp
bool equals_epsilon(double const a, double const b)
bool equals_epsilon(double const a, double const b)
{
return equals_epsilon(a, b, std::numeric_limits::epsilon());
}
```
```cpp
bool equals_epsilon(double const a, double const b, double const epsilon)
{
return std::abs(a - b) < epsilon;
}
```
Code snippet causing the issue:
```cpp
TEST_CASE("Test math functions", "[math]")
{
REQUIRE(math::equals_epsilon(3.14159265358979323846, 3.14159265358979323846));
REQUIRE(math::equals_epsilon(42, 42));
REQUIRE(!math::equals_epsilon(3.141592653589793, 3.141592653589794));
REQUIRE(!math::equals_epsilon(3.14159265358979323846, 3.14));
REQUIRE(!math::equals_epsilon(42, 42.1));
REQUIRE(!math::equals_epsilon(42, 43));
REQUIRE(math::equals_epsilon(math::to_rad(180), math::pi));
REQUIRE(math::equals_epsilon(math::to_deg(math::pi), 180));
REQUIRE(!math::equals_epsilon(math::to_rad(181), math::pi));
REQUIRE(!math::equals_epsilon(math::to_deg(math::pi), 181));
auto constexpr epsilon{ 1E-1 };
REQUIRE(math::equals_epsilon(3.14159265358979323846, 3.14159265358979323846, epsilon));
REQUIRE(math::equals_epsilon(42, 42, epsilon));
REQUIRE(math::equals_epsilon(3.141592653589793, 3.141592653589794, epsilon));
}
```
Note that all lines with a `REQUIRE` cause a warning.
**Platform information:**
- OS: **Windows 10**
- Compiler+version: **MSVC++ 14.27**
- Catch version: **v2.13.0**
**Additional context**
n/a
Contributor guide
Assessment
This issue has not been assessed yet.