从 istream 读取 bitset<0> 总是失败?

Reading bitset<0> from istream always a failure?

我最近在与 std::bitset<0> 合作,发现 operator>> 有一些有趣的事情:

"specification" 指出:

If no characters are extracted, is.setstate(ios_base::failbit) is called.

阅读 "all possible N characters"(N == 0)后,这是否仍然适用?如果是这样,这是否意味着尝试从 istream 读取到 bitset<0> 必须始终设置 failbit

以下单元测试在我手头的编译器中表现出不一致的行为:

BOOST_AUTO_TEST_CASE(io0) {
    try {
        std::stringstream ss{"1"};
        ss.exceptions(std::ios::badbit | std::ios::failbit);
        std::bitset<0> b;
        ss >> b;
        BOOST_TEST(false);
    } catch(...) {
        BOOST_TEST(true);
    }
}

MSVC 2019 设置了故障位,而 GCC 7.3.0 没有!

已针对 C++20 解决的 specification (no scare quotes) said the same thing (when this question was asked), so yes. (Of course, skipping whitespace first may provoke some other kind of failure instead.) I thought this a clear error in the standard, so I filed an issue