How to declare a familiar custom literal operator in a template class?

It is not clear why the code below does not compile with GCC g ++ 4.7, saying the following:

$ g++ -std=c++11 -fPIC test.cpp test.cpp:11:45: error: 'B operator"" _b(const char*, size_t)' has invalid argument list 

If class C is declared non-template, it compiles fine.

 #include <cstddef> struct B{}; B operator+(B, B) { return B(); } B operator"" _b(const char *, size_t) { return B(); } template<typename T> class C { friend B operator+(B, B); friend B operator"" _b(const char *, size_t); }; int main() { return 0; } 

What is wrong with this code? Or is this a compiler error?

+6
source share
1 answer

Or is this a compiler error?

This code is correct, since the signature of the operator function is explicitly allowed by the standard - see clause 13.5.8 / 3. So this is a GCC bug.

+3
source

Source: https://habr.com/ru/post/971453/


All Articles