The default gcc (4.6.x) on Ubuntu 12.04 is quite old, especially given the quick advance in C++11 capabilities in gcc 4.7 and 4.8 (and, importantly, their respective libstdc++ libraries).

The LLVM project has recently decided (and implemented, earlier this week) to set gcc 4.7 and Clang 3.1 as the minimal versions LLVM & Clang themselves would build with, in order to be able to use C++11 capabilities in the implementation. Therefore, if you want to build trunk LLVM & Clang on Ubuntu 12.04, you need a newer gcc (even if you use Clang to self-build, still libstdc++ version 4.7 or later is required).

Luckily, building a new gcc and installing it locally (to not mess with the system installation) is fairly easy. Here's a short sequences of steps.

First, create a place to hold the installation, like $HOME/install/gcc-4.8.2.

Install some dependencies needed to build gcc:

$ sudo apt-get install libmpfr-dev libgmp3-dev libmpc-dev flex bison

Then, get a gcc 4.8 tarball and unpack it:

$ wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.bz2
$ bunzip2  gcc-4.8.2.tar.bz2
$ tar xvf gcc-4.8.2.tar

Enter the untarred gcc directory:

$ cd gcc-4.8.2/
$ mkdir build
$ cd build

Now, configure and build:

$ ../configure --disable-checking --enable-languages=c,c++ \
  --enable-multiarch --enable-shared --enable-threads=posix \
  --program-suffix=4.8 --with-gmp=/usr/local/lib --with-mpc=/usr/lib \
  --with-mpfr=/usr/lib --without-included-gettext --with-system-zlib \
  --with-tune=generic \
  --prefix=$HOME/install/gcc-4.8.2
$ make -j8
$ make install

This places an installation of gcc 4.8.2 in $HOME/install/gcc-4.8.2. For example, you should be able to see this:

$ cd $HOME/install/gcc-4.8.2
$ find . -name gcc4.8
./bin/gcc4.8

That's it. You can try it:

$ cd /tmp
$ cat > test.c
int main() { return 42; }
$ $HOME/install/gcc-4.8.2/bin/gcc4.8 test.c
$ ./a.out; echo $?
42

You can also run gcc4.8 with the -### flag to see the exact compilation steps and notice which libraries get picked up, etc. (note that to see -lstdc++ a C++ source compiled with g++4.8 is needed instead).

As a bonus, trunk LLVM & Clang can be now build by passing this gcc to the configure script (the exact same idea works with the CMake-based configuration flow too):

$ CC=$HOME/install/gcc-4.8.2/bin/gcc4.8 \
  CXX=$HOME/install/gcc-4.8.2/bin/g++4.8 \
  ../../llvm-src/configure