在 clang++ 预处理器中确定 gcc-toolchain 版本

Determine gcc-toolchain version in clang++ preprocessor

根据cppreference,gcc libstdc++支持并行TS。用外行人的话说,对于与我相关的内容,这意味着 #include <execution> 在 g++ 9 中有效,在 g++ 8 或更早版本中无效。在我的源代码中,我可以用

来处理这个问题
#if ( defined( __GNUC__ ) && __GNUC__ > 8 )
#  define can_use_std_execution
#  include <execution>
#endif

对于我的 clang++ 构建,<execution> 的可用性取决于我使用的 --gcc-toolchain。因此,我不想检查 __clang_major__,而是想检查预处理器中的 gcc libstdc++ 版本。

据我所知in this compiler-explorer example,clang中定义了__GNUC__但是编译命令是

-g -o /tmp/compiler-explorer-compiler120120-1672-4ffux6.smufm/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-8.3.0 -fcolor-diagnostics -fno-crash-diagnostics /tmp/compiler-explorer-compiler120120-1672-4ffux6.smufm/example.cpp

即gcc 工具链来自 gcc 8.3.0,但 __GNUC__ 的值为 4.

用clang在预处理器中查询gcc工具链版本的好方法是什么?理想情况下,一种以与 g++ 和 clang++ 兼容的方式检查 libstdc++ 版本的方法,这样如果首先检查编译器,我就不必写意大利面条了。

在 gcc 9 的编译器头文件中寻找 ^#.*define.*9 似乎

#include <bits/c++config.h>
#if _GLIBCXX_RELEASE > 8
#  include <execution>
#endif

可以胜任。从 this conformance view 这个变量是在 gcc 7 的工具链中引入的。