小编qzh*_*ong的帖子

关于模板别名和用户定义运算符的顺序的奇怪行为

以下代码可以使用 MSVC(v19.38) 编译,但使用 GCC(13.2) 和 Clang(17.0.1) 编译失败。但旧版本的 GCC,例如 11.2,可以正常工作。

#include <type_traits>

#ifdef MY_INT
template<typename T, T V> struct my_int
{
        static constexpr T value = V;
        using value_type = T;
        constexpr operator value_type() const noexcept { return value; }
        constexpr value_type operator()() const noexcept { return value; }
};
template<auto V> using constant_int_t = my_int<decltype(V), V>;
#else
template<auto V> using constant_int_t = std::integral_constant<decltype(V), V>;
#endif

template<typename T1, typename T2>
using add_t = decltype(T1{} + T2{});

template<typename T1, typename T2>
constexpr …
Run Code Online (Sandbox Code Playgroud)

c++ name-lookup template-aliases clang++

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

标签 统计

c++ ×1

clang++ ×1

name-lookup ×1

template-aliases ×1