确定clang ++预处理程序中的gcc-toolchain版本

问题描述 投票:1回答:1

根据cppreference,gcc libstdc ++支持并行度TS。用非专业人士的话来说,对于我而言,这意味着#include <execution>在g ++ 9中有效,而在g ++ 8或更早版本中无效。在我的源代码中,可以使用

处理
#if ( defined( __GNUC__ ) && __GNUC__ > 8 )
#  define can_use_std_execution
#  include <execution>
#endif

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

据我所知in this compiler-explorer example__GNUC__是用clang定义的,但是编译命令是

-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 ++版本,这样,如果先检查编译器,我就不必写意粉。

c++ gcc clang++
1个回答
0
投票
#include <bits/c++config.h> #if _GLIBCXX_RELEASE > 8 # include <execution> #endif

可以胜任。从this conformance view开始,此变量与gcc 7的工具链一起引入。

© www.soinside.com 2019 - 2024. All rights reserved.