Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22000

Friend declaration of literal operator in class template

$
0
0

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?


Viewing all articles
Browse latest Browse all 22000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>