So I'm writing the [doctest](https://github.com/onqtam/doctest) library and it's supposed to be warning free.

I recently noticed that code that went into an `if` statement without warnings was causing trouble when written inside of my `CHECK()` macro.

For example: `if(0u == 0)` doesn't cause a warning but `CHECK(0u == 0);` does.

I investigated a bit and part of the reason is that behind the `CHECK()` macro there are templates and expression decomposition and capturing by const reference.

My questions are 3:

1. Given these 3 snippets - why does this happen?

gives a warning:

```
int a = 0;
unsigned b = 0;
if(a == b)

```

doesn't give a warning:

```
const int a = 0;
const unsigned b = 0;
if(a == b)

```

gives a warning:

```
const int& a = 0;
const unsigned& b = 0;
if(a == b)

```

2. How can I combat this? Obviously I can use `#pragma diagnostic` around the templates in the library header and silence these warnings but this will not be correct.

The reason is that if the following code gives a warning:

```
int a = 0;
unsigned b = 0;
if(a == b)

```

then the next piece of code should also give a warning:

```
int a = 0;
unsigned b = 0;
CHECK(a == b);

```

3. Is there something I'm missing about the const noref case? Because yesterday I posted [this](https://stackoverflow.com/questions/39075223) question which seems strikingly similar... Are there other cases that will bite me by the ass because of this capturing by const reference in my templates?

I don't think the compiler or the optimization levels matter - I've tried a few versions of g++/MSVC (`/W4` for msvc and `-Wall -Wextra -pedantic` + [50 more](https://github.com/onqtam/doctest/blob/master/scripts/common.cmake#L74) for g++) and probably clang does the same...

**EDIT:**

The following code produced a warning with g++ but did NOT with msvc... (`-Wsign-conversion`)

```
const int a = -1;
const unsigned b = 0;
if(a == b)

```