Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

Cannot convert non-capturing lambda closure to function pointer using the unary + operator

$
0
0

I've come up with an issue when trying to use some generic code involving lambda functions. Here it is a minimal code to reproduce it:

#include <iostream>
int main() {
    auto f = [] { std::cout << "this is a test"<< std::endl; };
    void(*fp0)() = f; // OK
    auto fp1 = +f;    // Does not compile
    fp0();
    fp1();
    return 0;
}

And this is the error the compiler raises:

error: more than one conversion function from "lambda []()->void" to a built-in type applies:
            function "lambda []()->void::operator void (*)()() const"
            function "lambda []()->void::operator void (*)()() const"
      auto fp1 = +f;    // Does not compile

The main problem with this bug is that it makes imposible to convert lambdas to regular function pointers in a generic context when you don't know the signature beforehand. I've tested the given code with another compilers and it just works. Currently I'm using Intel Parallel Studio XE 2019 Update 2.


Viewing all articles
Browse latest Browse all 1175

Trending Articles



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