Mario
Mario

Reputation: 36487

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

Upvotes: 6

Views: 234

Answers (1)

catnip
catnip

Reputation: 25388

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

Upvotes: 2

Related Questions