Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Possible bug in icc

Someone_E_
Beginner
288 Views

I am pretty sure the following program complies to C++ 0x standard. icc however cannot compile it:

 

#include <functional>

struct Node {
    size_t length;
};

template<typename N>
class C {
public:
  size_t longest = 0;
  std::function<void(const N )> f = [this](N node) {
    if(node->length > this->longest) this->longest = node->length;
  };
};

int main() {

  Node n;
  n.length = 5;
  C<Node*> c;
  c.f(&n);
}

The error is:

test_func.cc(12): error: "this" cannot be used inside the body of this lambda
      if(node->length > this->longest) this->longest = node->length;

 

I compile with icc (ICC) 14.0.2 20140120 using  -std=c++11 option

0 Kudos
2 Replies
Judith_W_Intel
Employee
288 Views

 

Yes I think you are correct. Both clang and Microsoft accept this (GNU gives an internal error).

It looks like our compiler gives an error because the use of "this" is not inside a non static member function (which I think is ok here).

I have entered DPD200257106 in our internal tracking database to track this defect. Thank you for bringing it to our attention.

Judy

0 Kudos
KitturGanesh
Employee
288 Views

Thanks Judy, I've updated the issue id to the thread for tracking purposes as well....

0 Kudos
Reply