I'm trying to make a class that can only be constructed through a literal operator, but it fails to build on gcc.
Here's a stripped down example:
#include <cstddef>
template<typename C>
class Foo;
Foo<char> operator "" _foo(const char*, std::size_t);
template<typename C>
class Foo
{
Foo() = default;
friend Foo<char> operator "" _foo(const char*, std::size_t);
};
Foo<char> operator "" _foo(const char* str, std::size_t size)
{
return Foo<char>();
}
int main()
{
auto foo = "Foo"_foo;
return 0;
}
It fails with this message: https://godbolt.org/z/kfcNMR
<source>:11:22: error: 'Foo<char> operator""_foo(const char*, std::size_t)' has invalid argument list
It works on clang and msvc, and without the template it works on gcc: https://godbolt.org/z/exfm5Q
Is this a compiler bug or am I making a mistake?