CLion 2018.1.2 inspection gives false error on lambda expression with template parameters

Answered

In CLion 2018.1.2 the following code causes CLion to give a "Parameter Type Mismatch" error.

e->addComponent<MockComponentOne>(
[](MockComponentOne* c){
c->x(12.0);
c->y(4.0);
});

Which it didn't in version 2018.1.1. The code compiles correctly and all test cases pass. I've uploaded a screenshot using the web form. The file name is error.png.

The signature of the addComponent method is:

template <class T> Status addComponent(std::function<void(T*)> init)

It complains that "Types: 'std::function<void(MockComponentOne*)>' and 'void(*)(MockComponentOne*)' are not compatible". Please fix. It's really annoying.

Thanks.

3
3 comments

It seems that it boils down to something broken in CLion 2018.1.2 related to assigning a lambda to std::function. A simple statement like:

std::function<void()> f = []() {};

Is underlined in red complaining that:

Types 'function<void()>' and 'void(*)()' are not compatible

Even tough it compiles just fine.

3

Here's the entire piece of code in question. It's a lambda inside a lambda.

frm::Status s = em.put(
MOCK_ENTITY_ONE,
[](frm::Entity* e) {
e->addComponent<MockComponentOne>(
[](MockComponentOne* c){
c->x(12.0);
c->y(4.0);
});
},
[](frm::Entity* e) {
e->removeComponent<MockComponentOne>();
});
2

Thanks. Currently the regression is under development/testing: https://youtrack.jetbrains.com/issue/CPP-12919

0

Please sign in to leave a comment.