clang++只在删除-std=c++11选项时使用boost::format编译c++11程序

clang++ only compiles C++11 program using boost::format when -std=c++11 option is dropped

本文关键字:c++11 boost format 程序 编译 选项 删除 -std clang++      更新时间:2023-10-16

请看下面的c++ 11代码片段:

#include <boost/format.hpp>
int main(int argc, char** argv)
{
  auto s = boost::format("");
  return 0;
}

当我使用-std=c++11编译clang时,我得到以下错误:

$ clang++ -std=c++11 -o main main.cpp
In file included from main.cpp:1:
In file included from /usr/include/boost/format.hpp:19:
In file included from /usr/include/boost/detail/workaround.hpp:41:
In file included from /usr/include/boost/config.hpp:40:
In file included from /usr/include/boost/config/select_stdlib_config.hpp:18:
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../include/c++/4.9.0/cstddef:51:11: error: 
      no member named 'max_align_t' in the global namespace
  using ::max_align_t;
        ~~^
1 error generated.

没有-std=c++11,一切都可以正常编译,但是clang打印了一个警告:

$ clang++ -o main main.cpp
main.cpp:5:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  auto s = boost::format("");
  ^

所以,看起来一个有效的解决方案是放弃c++ 11标志,因为当前版本的clang似乎处于c++ 11模式,不管怎样?缺点是你会得到很多警告。

除了完全切换到gcc之外,有没有更好的解决方案?修补boost::format或gcc-lib的源代码对我来说很好。


系统信息:

  • 平台:Arch Linux x86_64
  • Boost版本:1.55.0-6
  • gcc-libs: 4.9.0-1
  • clang++: 3.4 (tags/RELEASE_34/final)

该bug现已关闭。它应该在Arch中固定,clang 3.4-2。

在这个提交中,Evangelos Foutras从上游合并了以下补丁:http://reviews.llvm.org/rL201729