I have this code and GCC prints “what!?”. How can I avoid that, so that the void cast simply has the C meaning “Ignore the lonely ‘a;'”?
#include <iostream>
struct A {
template<typename T>
operator T() {
std::cout << "what!?";
}
};
int main() {
A a;
(void)a;
}
As you’ve observed, this is a bug in gcc. The standard reads:
As a workaround, you could write:
It’s impossible to overload
operator,(void)so there is zero chance of this invoking user-defined behaviour from a conformant implementation.