Using C++11 in clang-tools-extra Round 2

Near the end of November I first posed the question of using C++11 features in the clang-tools-extra repo. At the time I let the subject drop because of the problem identified of mixing standard libraries C++03 with C++11 between the llvm/clang builds and tools-extra. I'd like to look at this issue again.

What if we decide to make use of C++11 in tools-extra and make a C++11-enabled llvm/clang build be a requirement? As far as the build goes, we can support this by removing clang-tools-extra from the check-all target if C++11 is not enabled. I'm not sure how easy this is to detect but perhaps we can introduce a cmake/configure option to make 'detection' easier.

Should we make all tools in tools-extra C++11 enabled or have the tools 'opt-in'? I'd like to see cpp11-migrate use C++11 considering its purpose but clang-format sees a lot of work these days too and I'm not sure if that tool wants to be C++11-enabled too?

Near the end of November I first posed the question of using C++11 features in the clang-tools-extra repo. At the time I let the subject drop because of the problem identified of mixing standard libraries C++03 with C++11 between the llvm/clang builds and tools-extra. I'd like to look at this issue again.

What if we decide to make use of C++11 in tools-extra and make a C++11-enabled llvm/clang build be a requirement? As far as the build goes, we can support this by removing clang-tools-extra from the check-all target if C++11 is not enabled. I'm not sure how easy this is to detect but perhaps we can introduce a cmake/configure option to make 'detection' easier.

Should we make all tools in tools-extra C++11 enabled or have the tools 'opt-in'? I'd like to see cpp11-migrate use C++11 considering its purpose but clang-format sees a lot of work these days too and I'm not sure if that tool wants to be C++11-enabled too?

C++11 library support on OS X requires libc++, which in turn means
that binaries won't run on OS X versions earlier than 10.7. Then
again, newer Xcodes don't support 10.6 any more, so it's probably not
a big deal. Just wanted to point this out.

Likewise, libstdc++ doesn't build with -std=libc++ on linux either
(with libstdc++ 4.4, 4.6, 4.7). How available is libc++ on linux
systems? Do most distros offer a package for it?

Nico

Nico wrote:
C++11 library support on OS X requires libc++, which in turn means
that binaries won't run on OS X versions earlier than 10.7. Then again, newer Xcodes don't support 10.6 any more, so it's probably not a big deal. Just wanted to point this out.

[Edwin] Unless there's a lot of users of clang-tools-extra using older versions of OSX I don't we need to worry.

Likewise, libstdc++ doesn't build with -std=libc++ on linux either (with libstdc++ 4.4, 4.6, 4.7). How available is libc++ on linux systems? Do most distros offer a package for it?

[Edwin] I'm not sure I understand. Is the build of libstdc++ part of the standard llvm/clang/tools-extra build? I understood it to be a completely separate project. If so it won't impact using C++11 in tools-extra unless I'm missing the point.

Bringing list up to speed. My mail client lead me to believe this was actually already on the list...

Nico wrote:
libstdc++ is not part of tools-extra. But if you want to build C++11
code with clang on linux, you need to use libc++ because clang can't parse libstd++ (the default c++ library) in c++11 mode. And if you use
libc++, users now have to have libc++ to run the tools-extra binaries.

[Edwin] I checked with coworkers here and they have built llvm/clang with c++11 support with libstd++ before. To qualify that, they use configure, specify --enable-cxx11, and build llvm/clang. If libc++ really is necessary that can be an extra requirement. It's easy enough to check out and build oneself.

Nico wrote:
libstdc++ is not part of tools-extra. But if you want to build C++11
code with clang on linux, you need to use libc++ because clang can't
parse libstd++ (the default c++ library) in c++11 mode. And if you use
libc++, users now have to have libc++ to run the tools-extra binaries.

[Edwin] I checked with coworkers here and they have built llvm/clang with c++11 support with libstd++ before. To qualify that, they use configure, specify --enable-cxx11, and build llvm/clang.

Sure, you can build clang itself, but building programs that use c++11 don't Just Work as far as I can tell:

thakis@yearofthelinuxdesktop:/usr/local/google/chrome/src$ cat test.cc #include <iostream>

int main() {}
thakis@yearofthelinuxdesktop:/usr/local/google/chrome/src$
third_party/llvm-build/Release+Asserts/bin/clang++ test.cc thakis@yearofthelinuxdesktop:/usr/local/google/chrome/src$
third_party/llvm-build/Release+Asserts/bin/clang++ test.cc -std=c++11 In file included from test.cc:1:
In file included from
/usr/lib/gcc/x86_64-linux-gnu/4.4/../../../../include/c++/4.4/iostream:39:
In file included from
/usr/lib/gcc/x86_64-linux-gnu/4.4/../../../../include/c++/4.4/ostream:39:
In file included from
/usr/lib/gcc/x86_64-linux-gnu/4.4/../../../../include/c++/4.4/ios:39:
In file included from
/usr/lib/gcc/x86_64-linux-gnu/4.4/../../../../include/c++/4.4/exception:148:
/usr/lib/gcc/x86_64-linux-gnu/4.4/../../../../include/c++/4.4/exception_ptr.h:143:13:
error: unknown type name
      'type_info'
      const type_info*
            ^
1 error generated.

If libc++ really is necessary that can be an extra requirement. It's easy enough to check out and build oneself.

libc++ is probably a system-level shared library if it's installed
through a package manager. A self-built libc++ would probably clash with that. It's also not that easy to build, as it depends on a libcppsup and an unwind library, which too might clash with system libraries.

On FreeBSD we have a similar situation. libc++ can work, but won't be part of the base system's default install until 9.2 (which should be soon, since 9.1 was massively delayed). Currently, I don't think the build logic for building libc++ as part of the LLVM build will correctly detect the libcxxrt that we have in the base system.

It would be a shame to make development difficult on the two platforms that have switched to clang as the default compiler...

David

Keep in mind that building clang/llvm with c++11 support would only be a requirement for those working with the tools-extra repository and even then we can further restrict to only the tools within that repo that want to use c++11. This is a small crowd so even if we have to use libc++ it's not going to have a big impact.

It occurred to me that the clang I was building with was not itself c++11 enabled. So I did a full build of llvm/clang from trunk using these commands:

configure --enable-cpp11
make install -j4

Then I built the simple test case you had. Still no error. From looking around I see other people get the error with gcc 4.7 (c++ - When enabling C++11 with stdlibc++ 4.7, clang error out, while gcc compiles fine - Stack Overflow) so maybe that's the problem here.

In any case, would it be a problem to build llvm/clang with c++11 enabled just for the libraries to link into the tools of tools-extra but do the actual build with a clang not built with -std=c++11?