C++ 叮当声;constexpr函数求值 Clang和constexpr表达式/函数求值
上下文:C++ 叮当声;constexpr函数求值 Clang和constexpr表达式/函数求值,c++,clang,c++17,c++20,clang++,C++,Clang,C++17,C++20,Clang++,上下文: 作为免责声明,关于Clang计算constexpr表达式的方式,以及为什么它可能不同于GCC、MSVC和其他编译器,在堆栈溢出上有许多问题。 然而,只有一个标准,对我来说,重要的是哪一个编译器的最新版本在“T”时间实现,而它没有 考虑以下代码(完整示例): 模板 类索引{ 模板 consteval static auto impl() { 使用ArgsAsTuple=pack\u arguments\u作为; constexpr自动索引=[](标准::索引_序列)conste
- 作为免责声明,关于Clang计算constexpr表达式的方式,以及为什么它可能不同于GCC、MSVC和其他编译器,在堆栈溢出上有许多问题。
然而,只有一个标准,对我来说,重要的是哪一个编译器的最新版本在“T”时间实现,而它没有
模板
类索引{
模板
consteval static auto impl()
{
使用ArgsAsTuple=pack\u arguments\u作为;
constexpr自动索引=[](标准::索引_序列)constexpr
//->std::size\u t(有关此评论的详细信息,请参见下文)
{
constexpr auto matches=std::array{std::is_same_v…};
返回距离_算法(匹配);
}(参数索引序列{});
静态断言(index!=std::tuple_size_v,“index_of:no match”);
收益指数;
}
constexpr static auto from_begin=[](ContainerType容器)constexpr
{
返回std::distance(std::cbegin(容器),std::find(std::cbegin(容器),std::cend(容器),true));
};
公众:
constexpr static inline auto value=impl();
};
这会在Clang++最新版本(目前为12.0.0)上产生以下错误:
另外,std::array
构造函数是constexpr,以及自C++17以来的std::distance
算法
问题:
因此,我想知道并想了解:
-
< Clang >为什么不考虑这样的表达式-<代码>索引>代码>初始化——作为一个常量表达式,特别是在其他编译器?< /p>
- 如果是这样的话,编译器还没有实现的C++17或C++20中的哪一项功能的建议
- 是否存在不依赖于特定于叮当声的实现的工作环境?(例如使用
预处理器指令)#if uuu-clang_uu
感谢您迄今为止的阅读和分享您的知识。您期望得到什么?对于该调用,我期望编译失败,希望通过“index_of:no match”断言失败。
error: invalid operands to binary expression ('const auto' and 'int')
static_assert(index_of<char>::value == 1);
source>:55:28: error: constexpr variable 'index' must be initialized by a constant expression
constexpr auto index = []<std::size_t... I>(std::index_sequence<I...>) constexpr
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:79:46: note: in instantiation of function template specialization 'gcl::mp::type_traits::index_of<char, std::tuple<int, char, double, int, char>>::impl<{}>' requested here
constexpr static inline auto value = impl<from_begin>();
^
...