Функция шаблона-шаблона перегружает ошибку неоднозначности с использованием gccC++

Программы на C++. Форум разработчиков
Anonymous
Функция шаблона-шаблона перегружает ошибку неоднозначности с использованием gcc

Сообщение Anonymous »

У меня этот код отлично работает на clang

Код: Выделить всё

template 
struct CollectIntoAllocatedContainer
{
// ...
};

template 
struct CollectIntoAllocatedContainerWithCharTraits
{
// ...
};

template 
constexpr CollectIntoAllocatedContainer collect()
{
return {};
}

template 
constexpr CollectIntoAllocatedContainerWithCharTraits collect()
{
return {};
}

int main() {
collect().dosomething();
collect().dosomething();
}
Но на gcc происходит сбой с ошибкой:

Код: Выделить всё

error: call of overloaded ‘collect()’ is ambiguous
78 |     collect();
|     ~~~~~~~~~~~~~~~~~~~~~~~~~~^~
note: candidate: ‘constexpr CollectIntoAllocatedContainer collect() [with T = std::__cxx11::basic_string]’
64 | constexpr CollectIntoAllocatedContainer collect()
|                                            ^~~~~~~
note: candidate: ‘constexpr CollectIntoAllocatedContainerWithCharTraits collect() [with T = std::__cxx11::basic_string]’
70 | constexpr CollectIntoAllocatedContainerWithCharTraits collect()
|                                                          ^~~~~~~
Я пробовал концепции:

Код: Выделить всё

template 
concept AllocatedContainer = requires(V x) {
typename T;
};

template 
concept AllocatedContainerWithCharTraits = requires(V x) {
typename T;
};

template 
constexpr CollectIntoAllocatedContainer collect()
requires AllocatedContainer
{
return {};
}

template 
constexpr CollectIntoAllocatedContainerWithCharTraits collect()
requires AllocatedContainerWithCharTraits
{
return {};
}
но безрезультатно
Я использую:
  • gcc 13.3.0
  • clang 17.0.2 (android, Armv7, ndk: 26.1.10909125)
Это ошибка gcc? Или clang ошибочно допускает такой код? Есть ли обходной путь? Спасибо за помощь.
P.S: Я не могу менять версии компиляторов, так как они привязаны к корпоративной инфраструктуре моей компании.

Подробнее здесь: https://stackoverflow.com/questions/793 ... -using-gcc

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