7

Please take a look at the following C++11 snippet:

#include <boost/format.hpp>

int main(int argc, char** argv)
{
  auto s = boost::format("");
  return 0;
}

When I compile it with clang using the -std=c++11 I get the following error:

$ 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.

Without the -std=c++11 everything compiles fine, but clang prints a warning:

$ 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("");
  ^

So, it looks like a valid workaround is to drop the C++11 flag, as the current version of clang seem to be in C++11 mode, anyway? The drawback is that you will get many warnings.

Is there a better workaround beside completely switching to gcc? Patching the source code of boost::format or gcc-libs is fine for me.


System information:

  • Platform: Arch Linux x86_64
  • Boost version: 1.55.0-6
  • gcc-libs: 4.9.0-1
  • clang++: 3.4 (tags/RELEASE_34/final)
Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
  • 5
    Sounds like [a bug from clang with libstdc++ 4.9](https://bbs.archlinux.org/viewtopic.php?pid=1412317). – Chnossos May 05 '14 at 00:02
  • Reminder: you can't just drop `std=c++11` on a single TU to workaround any issues because that will potentially break ODR for all entities declared in (headers included in) that TU. Down that path lies [UB](http://en.wikipedia.org/wiki/Undefined_behavior). So droppping c++11 would mean dropping it for all of your project (unless your TU includes nothing) – sehe May 05 '14 at 00:49
  • 4
    Works great with libc++ instead of libstdc++, and with libstdc++ that came with gcc 4.8. I suspect that was this change: http://gcc.gnu.org/gcc-4.9/porting_to.html (search for max_align_t) – Marshall Clow May 05 '14 at 00:55
  • @Chnossos You are right. It is the exactly this issue. Thank you for the link. – Philipp Claßen May 05 '14 at 01:23
  • Here is a bug report: https://bugs.archlinux.org/task/40229 – Philipp Claßen May 05 '14 at 18:57

1 Answers1

2

The bug is closed now. It should be fixed in Arch with clang 3.4-2.

With this commit, Evangelos Foutras merged the following patch from upstream: http://reviews.llvm.org/rL201729

Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239