How do I build gcc with C++ concepts (“concepts lite”) support?

烂漫一生 提交于 2019-11-30 10:45:28

As of Fri, 7 Aug 2015 01:44:49 -0400 (05:44 +0000) concepts support has been merged into gcc's trunk.

Using a build from after that point, you can enable concepts support with the -std=c++1z flag.

As of gcc 6.1 (27-04-2016), concepts are enabled by -fconcepts as they are unlikely to be included in C++17, so they have been removed from -std=c++1z. (via @BruceAdams in comments below)

According to Andrew Sutton the git mirror of the Concepts Lite work is entirely out of date and shouldn't be used. There is a concepts branch in the svn repository for gcc implementing "concepts-lite" (there was a pre-C++11 effort to add concepts to C++ which was abandoned; a new effort to add concepts to C++ was started using the name concepts lite). It is fairly straight forward to build (assuming you already have a recent gcc and the packages it depends on installed; see the gcc install instruction for other options you might want to pass: the instructions below worked for me except that I explicitly pointed configure at the locations where gmp, mpc, and mpfr are installed):

cd <suitable-directory>
svn checkout svn://gcc.gnu.org/svn/gcc/branches/c++-concepts
mkdir build-concepts
cd build-concepts
../c++-concepts/configure --prefix=<concept-gcc-root> --disable-bootstrap --enable-languages=c,c++
make -j8
make install

What isn't entirely obvious is how to actually use concepts: the option -fconcepts does exist but seems to unconditionally do something different than enabling concepts-lite. Instead, you'd use the -std=c++1z option when compiling with concepts enabled.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!