I've been doing constrained partial class template specializations using C++20 concepts for a while now and they work great, but I and ran into a problem when attempting to forward declare them: godbolt example
#include <concepts>
template <class T>
concept Integer = std::is_same_v<T,int> || std::is_same_v<T,unsigned int>;
template <class T>
concept Float = std::is_same_v<T,float> || std::is_same_v<T,double>;
template <class T>
class S
{};
template <Integer T>
class S<T>;
// This forward declaration breaks GCC
template <Float T>
class S<T>;
template <Integer T>
class S<T>
{};
template <Float T>
class S<T>
{};
int main()
{
S<int> s_int;
S<float> s_float;
}
The second forward declaration
// This forward declaration breaks GCC
template <Float T>
class S<T>;
breaks GCC, but Clang and MSVC have no issues with it. I've had very similar problems with concepts in the past (which still haven't been fixed yet) but it was the other way around: GCC was conformant yet Clang and MSVC incorrectly rejected the code.
Ditching concepts and explicitly specializing for int
and float
is accepted by GCC as well (godbolt example).
Any ideas what's going on here?
Was a bug; is now fixed. No idea which version this fix will make it into.