#include <iostream>
int main() {
bool b = true;
std::cout << std::is_same<decltype(!(!b)), bool>::value << "\n";
auto bb = (!(!b));
std::cout << std::is_same<decltype(bb), bool>::value << "\n";
}
The above code has different results using different compilers. Is this a compiler bug or am I missing something?
- clang 1 1 (https://godbolt.org/z/s43T55rxq)
- msvc 1 1 (https://godbolt.org/z/YnKfKh41q)
- gcc 0 1 (https://godbolt.org/z/91xdfv93c)
This is a gcc bug. The problem is that gcc incorrectly treats the expression
!(!b)as an lvalue instead of rvalue. You can confirm this here. As you'll see in the above linked demo, the output gcc gives islvalueinstead ofprvalue.The bug has been reported as:
GCC treats rvalue as an lvalue