Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Lambda taking std::unique_ptr by value does not compile unless it captures something

$
0
0
#include <memory>

int main(){

   int makeitcompile;
   [makeitcompile](std::unique_ptr<int> ICompile){}; //<--- This compiles.
   [](std::unique_ptr<int> IDoNotCompile){};             //<--- This does not.

   return 0;

}



Tried it in VS2012.3 and VS2013.Preview. 

A lambda that captures nothing but takes a unique_ptr by value will not compile. It trys to access the copy constructor of the unique_ptr which is obviously private. The extremely strange part is that if you have it capture a value, everything is happy, as shown above.

I can only assume this is a compiler bug since it obviously doesn't actually have to copy anything since the closures aren't being called.

EDIT:

I found a similar bug report on Microsoft Connect that suggests that they admit it is a compiler bug and that they won't fix it. ID#785222 


TLDR, though I thought I was on a support forum so I should hope you read it:

Am I misunderstanding the C++ Standard or is this a compiler bug?


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>