#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";
}
上述代码在不同的编译器中结果不同。
这是编译器的错误还是我的错?
- clang 1 1 (https://godbolt.org/z/s43T55rxq)
- msvc 1 1 (https://godbolt.org/z/YnKfKh41q)
- gcc 0 1 (https://godbolt.org/z/91xdfv93c)
!!b
是一个左值,所以decltype
报告bool &
。它甚至允许!!b = false;
。看起来像是一个明显的错误,请报告此问题。相同的情况也会发生在任何偶数个!
之间。 - HolyBlackCat