std::is_same different results between compilers

2.4k views Asked by At
#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?

1

There are 1 answers

2
user12002570 On

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 is lvalue instead of prvalue.

The bug has been reported as:

GCC treats rvalue as an lvalue