为什么std :: boolalpha在使用clang时会忽略字段宽度?

Chi*_*iel 8 c++ io stringstream ostringstream c++11

以下代码使用g ++ 7编译器和Apple clang ++给出了不同的结果.在使用bool输出时std::boolalpha,我是否碰到了铿锵声中的错误,或者我犯了错误?

#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>

template<typename T>
void print_item(std::string name, T& item) {
    std::ostringstream ss;
    ss << std::left << std::setw(30) << name << "= " 
       << std::right << std::setw(11) << std::setprecision(5) 
       << std::boolalpha << item << " (blabla)" << std::endl;

    std::cout << ss.str();
}

int main() {
    int i = 34;
    std::string s = "Hello!";
    double d = 2.;
    bool b = true;

    print_item("i", i);
    print_item("s", s);
    print_item("d", d);
    print_item("b", b);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

不同之处是:

// output from g++ version 7.2
i                             =          34 (blabla)
s                             =      Hello! (blabla)
d                             =           2 (blabla)
b                             =        true (blabla)
// output from Apple clang++ 8.0.0
i                             =          34 (blabla)
s                             =      Hello! (blabla)
d                             =           2 (blabla)
b                             = true   (blabla)
Run Code Online (Sandbox Code Playgroud)

gsa*_*ras 5

在提到的TC,这是LWG 2703:

设置时没有填充填充boolalpha的规定

N4582子条款25.4.2.2.2 [facet.num.put.virtuals]第6段在其行为规范中没有规定填充填充 (str.flags() & ios_base::boolalpha) != 0.

因此,我没有看到与Clang的解决方案.但请注意:

  • libc ++完全实现了这一点.
  • libstdc ++和MSVC应用填充和对齐.

PS:LWG代表图书馆工作组.