clang 3.4 C++14 support

2.3k views Asked by At

I am using travis.ci to do automated test builds of my git repositories.

For linux they use: Ubuntu 12.04
With clang 3.4

According to the clang page all C++ 14 language features are supported by Clang 3.4 (as long as you use the -std=c++1y flag).

So far so good:
I also need to use std::index_sequence<t0,...,tn> which is library feature N3658 not a language feature. But I can not find any specific documentation on updating the C++ standard library for clang to make sure this feature is supported (it is not supported out of the box).

TestCode:

#include <utility>
int main() {
    std::index_sequence<1,2,3,4>    seq;
}

TestBuild:

> clang++ -std=c++1y pl.cpp
pl.cpp:3:10: error: no member named 'index_sequence' in namespace 'std'
    std::index_sequence<1,2,3,4>    seq;
    ~~~~~^
pl.cpp:3:37: error: use of undeclared identifier 'seq'
    std::index_sequence<1,2,3,4>    seq;
                                    ^
2 errors generated.

Update:

Based on the suggestion below I tried to use libc++.
Pretty sure I did something wrong but I have never tried to use an alternative standard library so am not sure what is going wrong here. Will digg in tonight. But if you have a suggestion then please leave a comment.

> sudo apt-get install -qq libc++1 libc6 libc++-dev

> clang++ -stdlib=libc++ pl.cpp
pl.cpp:1:10: fatal error: 'utility' file not found
#include <utility>
         ^
1 error generated.
2

There are 2 answers

0
Martin York On BEST ANSWER

Well the answer seems to be to install g++-4.9 This will update the standard libraries already installed to a point where clang will be able to compile the code.

sudo apt-get install python-software-properties
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9

## Because I also use llvm-cov from my makefile
## I have to make sure it is in the path.
a=$(sudo find / -name llvm-cov | head -1)
sudo ln -s ${a} /usr/bin/llvm-cov

So this is what I added to travis.yml file

before_install:
    - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test;fi
    - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then sudo apt-get update;fi
    - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then sudo apt-get install g++-4.9;fi
    - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then a=$(sudo find / -name llvm-cov | head -1);sudo ln -s ${a} /usr/bin/llvm-cov;fi

After I consolidate my g++ and clang++ pre-build code:

before_install:
    - if [ "$TRAVIS_OS_NAME" == "linux"];                         then sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y;fi
    - if [ "$TRAVIS_OS_NAME" == "linux"];                         then sudo apt-get update;fi
    - if [ "$TRAVIS_OS_NAME" == "linux"];                         then sudo apt-get install -qq g++-4.9;fi
    - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "g++" ];     then sudo update-alternatives --install /usr/bin/gcc  gcc  /usr/bin/gcc-4.9  90;fi
    - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "g++" ];     then sudo update-alternatives --install /usr/bin/g++  g++  /usr/bin/g++-4.9  90;fi
    - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "g++" ];     then sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-4.9 90;fi
    - if [ "$TRAVIS_OS_NAME" == "linux" -a "$CXX" == "clang++" ]; then a=$(sudo find / -name llvm-cov | head -1);sudo ln -s ${a} /usr/bin/llvm-cov;fi
5
Technaton On

According to https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html, libstdc++ supports this at least given the most recent version. Ubuntu 12.04 contains GCC 4.4, where this is obviously not supported. precise-backports does not contain a newer version of libstdc++.

However, via https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test, newer versions of GCC and with it, libstdc++, can be obtained. I don't know whether Travis supports installing from other repositories, or not, though.