Since C++11, it has been possible to create User Defined Literals. As expected, it's possible to return complex structs from such literals. However, when trying to use such operators as 123_foo.bar()
:
struct foo {
int n;
int bar() const { return n; }
};
constexpr foo operator ""_foo(unsigned long long test)
{
return foo{ static_cast<int>(test) };
}
int main() {
return 123_foo.bar();
}
GCC and Clang reject it, saying they can't find an operator""_foo.bar
. MSVC accepts it. If I instead write 123_foo .bar()
, all three compilers accept it
Who is right here? Is 123_foo.bar()
ever valid?
Some extra information:
- All three accept it for string literals
- The problem exists for
std::chrono
literals as well
I'm inclined to believe that this is a GCC and Clang bug, as .
is not part of a valid identifier.