gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:35:55 25 4
gpt4 key购买 nike

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

最佳答案

在gcc 9的编译器 header 中抓取^#.*define.*9似乎

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

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

关于c++ - 在clang++预处理器中确定gcc-toolchain版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60318611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com