Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang error – Compiler bug or missing some detail?

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

like image 716
Mario Avatar asked Jun 15 '18 23:06

Mario


1 Answers

Looks like a bug in clang, try this, and indeed this.

like image 168
Paul Sanders Avatar answered Oct 05 '22 19:10

Paul Sanders