While experimenting a bit with variadic templates, initializer lists, etc. I accidentally stumbled over the following nonsense-code triggering a rather interesting error message.
First, let's define a small class for testing with an overloaded operator,()
:
class Dummy {
public:
Dummy() {}
Dummy &operator,(int) { return *this; }
};
Now we're using this class in the following way:
int test1 = (Dummy{}, 0);
When compiling with clang version 6.0.0 (tags/RELEASE_600/final 334239)
this triggers a very legitimate sounding error message (since the operator essentially strips the 0
from the back):
error: no viable conversion from 'Dummy' to 'int'
Now let's change this example a tiny bit:
int test2 { (Dummy{}, 0) };
For my understand, this should basically trigger the same message, because in the end we're trying to do the very same thing here. However, the error is different:
error: no viable conversion from 'void' to 'int'
Big question: Is the void
a bug here or is there some conversion or interpretation happening I'm simply missing?
Code snippet on Compiler Explorer
Looks like a bug in clang, try this, and indeed this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With