Extremely cursed code of the day:

struct A {
void f(int) const;
void f(const std::string&);
};

void b() {
A a;
a.f(1); // Well-formed
a.f(0); // Ill-formed?!?!?!?
}

Godbolt: godbolt.org/z/qbEzz6hhv

It is worse b/c clang reject, gcc accepts w/ diagnostic and MSVC silently accepts 🤯

#Cplusplus

Follow

@shafik Yeah, 0 is cursed in c++ because it is also the null pointer literal aka NULL. Since string has a const char* overload, this is ambiguous because the compiler can interpret 0 as std::string(NULL).

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.