用g ++和clang ++打破std :: get_time吗?

Edw*_*ard 13 c++ time c++11 c++14

我今天正在使用一些时间函数,并注意到使用%r(或%p)的标准转换似乎不适用于通过std::get_time()g ++或clang ++ 进行输入.请参阅 g ++和clang ++的实时代码版本.这确实似乎窗户用VC下按预期运行++(见密切相关的问题).另请注意,无论是否imbue包含该行,效果都相同.我的Linux机器上的语言环境设置为"en_US.UTF-8"重要.

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

int main(){
    std::tm t{};
    std::stringstream ss{"1:23:45 PM"};
    ss.imbue(std::locale(std::cin.getloc(), 
             new std::time_get_byname<char>("en_US")));
    ss >> std::get_time(&t, "%r");
    if (ss.fail()) {
        std::cout << "Conversion failed\n" << std::put_time(&t, "%r") << '\n';
    } else {
        std::cout << std::put_time(&t, "%r") << '\n';
    }
}
Run Code Online (Sandbox Code Playgroud)

Edw*_*ard 11

正如评论者指出的那样,这实际上是一个错误(遗漏)libstdc++.一个错误报告已提交.