Почему эта перегрузка оператора компилируется в MSVC и GCC, но не в Clang?C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Почему эта перегрузка оператора компилируется в MSVC и GCC, но не в Clang?

Сообщение Anonymous »

Я пытаюсь создать тип-оболочку Strong_alias, который взаимозаменяем с примитивными типами, но не с другими типами Strong_alias.
#include
#include

template
requires std::is_arithmetic::value
class strong_alias
{
public:
using type = T;

constexpr strong_alias() : _value{}
{
}

template
requires std::is_arithmetic::value
constexpr strong_alias(const other &set_value) : _value{T(set_value)}
{
}

constexpr T &value()
{
return _value;
}

constexpr const T &value() const
{
return _value;
}

template
requires std::is_arithmetic::value
constexpr operator other() const
{
return other(value());
}

constexpr bool operator==(const strong_alias &rhs) const
{
return value() == rhs.value();
}

constexpr strong_alias operator*(const strong_alias &rhs) const
{
return value() * rhs.value();
}

private:
T _value;
};

using A = strong_alias;
static_assert(std::is_assignable());
static_assert(std::is_assignable());
static_assert(std::is_assignable());

using B = strong_alias;
static_assert(not std::is_assignable());
static_assert(not std::is_assignable());

static_assert(A(-3) == A(3) * -1); // builds with MSVC and GCC but not Clang

int main()
{
}

Приведенный выше код компилируется с помощью MSVC (/std:c++latest) и GCC (-std=c++2c), но не Clang (-std=c++2c). Демо-версия Compiler Explorer здесь.
Какой компилятор(ы) правильно обрабатывает этот код? Каков предпочтительный способ заставить это работать под Clang?
Вывод Clang из Compiler Explorer:
61 | static_assert(A(-3) == A(3) * -1); // builds with MSVC and GCC but not Clang
| ~~~~ ^ ~~
:43:25: note: candidate function
43 | constexpr strong_alias operator*(const strong_alias &rhs) const
| ^
:61:29: note: built-in candidate operator*(float, int)
61 | static_assert(A(-3) == A(3) * -1); // builds with MSVC and GCC but not Clang
| ^
:61:29: note: built-in candidate operator*(double, int)
:61:29: note: built-in candidate operator*(long double, int)
:61:29: note: built-in candidate operator*(int, int)
[...many lines omitted...]
:61:29: note: built-in candidate operator*(unsigned long long, unsigned long)
:61:29: note: built-in candidate operator*(unsigned long long, unsigned long long)
:61:29: note: built-in candidate operator*(unsigned long long, unsigned __int128)
1 error generated.
Compiler returned: 1


Подробнее здесь: https://stackoverflow.com/questions/784 ... -not-clang
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»