Testing C++ concepts with GCC 6.0 beta.

By , last updated September 29, 2016

This is a very terse list of steps to be done to be able to start testing concepts with G++.

While this article is still relevant, there is lots of more relevant information about Concepts Lite in the articles section. It has many articles not just on how to build GCC, but also how to use Concepts Lite and what types of concepts there are.

Building a beta version of GCC 6.0 Beta

  1. As root, make a user account for testing GCC:
    useradd -m betagcc
  2. Change to the new user:
    su - betagcc
  3. Clone GCC from somewhere. The mirror on GitHub is as good as any:
    git clone https://github.com/gcc-mirror/gcc.git
  4. Wait a moment for everything to clone.
  5. Enter the gcc folder:
    cd gcc
  6. Configure with C and C++ enabled. Note the use of ${HOME}. The prefix doesn’t expand the bash tilde ~, a full path must be used.:
    ./configure --disable-bootstrap --enable-languages=c,c++ --prefix=${HOME}/gccbin
  7. Make. This will take a long time. Speed up the process by using the -j parameter with number of cores in your system.
    make -j3
  8. Run make install to install to the gccbin directory.
    make install
  9. Make a bin-folder if you don’t have it already.
    mkdir -p ~/bin
  10. Create a symbolic link from /home/betagcc/bin/g++ to /home/betagcc/gccbin/bin/g++.
    ln -sf ${HOME}/gccbin/bin/g++ ~/bin/g++
  11. Add ~/bin to PATH. Add it to the beginning because you’re overriding g++ from the system. Add this line to .bashrc:
  12. Source .bashrc to add ~/bin to your path.
    source .bashrc
  13. Test that you’re using the correct g++ version with -v.
    $ g++ -v
    Using built-in specs.
    Target: x86_64-pc-linux-gnu
    Configured with: ./configure --disable-bootstrap --enable-languages=c,c++
    Thread model: posix
    gcc version 6.0.0 20150807 (experimental) (GCC)

Try building with concepts

Makefile below.

// concepts.cpp
#include <type_traits>

concept Stack<typename X> {
    typename value_type;
    void push(X&, const value_type&);
    void pop(X&);
    value_type top(const X&);
    bool empty(const X&);

concept_map InputIterator<char*> {
    typedef char value_type;
    typedef char& reference;
    typedef char* pointer;
    typedef std::ptrdiff_t difference_type;

template<typename T>
//requires std::is_arithmetic<T>::value
requires false
class Foo

struct B

int main()
        Foo<int> a;

        return 0;

Makefile: Remember to use the --std=c++1z switch. Without it, concepts will not be available.

        g++ --std=c++1z concepts.cpp -o concepts

This will print an error similar to:

g++ --std=c++1z concepts.cpp -o concepts
concepts.cpp: In function ‘int main()’:
concepts.cpp:34:9: error: template constraint failure
  Foo<int> a;
concepts.cpp:34:9: note:   constraints not satisfied
concepts.cpp:34:9: note:   ‘false’ evaluated to false
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1

This is a very brief introduction to concepts and how to build G++ with concepts enabled.


  1. serkan April 10, 2016 Leave a Reply

    Thank you for the post. I helped me to install gcc 6.0 without having any problem with the one installed on my machine.
    PS: After make (7) make install is needed.

    • kent April 10, 2016 Leave a Reply


      Thanks for noticing the missing make install. I’ve added it to the list


Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>