小编Jor*_*dan的帖子

C++ 概念,如何检查 constexpr static int 是否等于 1,或类似...?Clang 不同意 GCC 和 MSVC

我无法在cpprefference上找到与成员匹配的概念的正确语法static constexpr。此代码可以在 GCC 和 MSVC 上编译并正常运行,但在 Clang 中不起作用。我想知道是否有人知道这是我的错误,还是 GCC 和 MSVC 或 Clang 的问题?这是所有三个编译器都打开的Godbolt,我认为它说明了这一点!

#include <concepts>
#include <iostream>

template<typename T>
concept MyConcept = requires (T t){
    requires t.member == 1;

    //[clang's error]
    // note: because 't.member == 1' would be invalid: 
    //       constraint variable 't' cannot be used in an evaluated context
};

struct S {
    constexpr static int member {2};
};
struct D {
    constexpr static int member {1};
};

template<MyConcept …
Run Code Online (Sandbox Code Playgroud)

c++ constexpr c++-concepts c++20

4
推荐指数
1
解决办法
924
查看次数

标签 统计

c++ ×1

c++-concepts ×1

c++20 ×1

constexpr ×1