- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Tags:
- CC++
- Development Tools
- Intel® C++ Compiler
- Intel® Parallel Studio XE
- Intel® System Studio
- Optimization
- Parallel Computing
- Vectorization
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What other compilers you have tested? and what Microsoft VS version are you using?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've tested it also with gcc, clang, apple-clang and msvc.
In the case of gcc and clang, the example works with fairly old versions of them. gcc is able to compile it since its version 4.7 and clang since its version 3.5.
msvc had also the same problem, it works since version 19.14 onwards.
I am running icl directly from the command line, not from Visual Studio; but in case it is helpful, the current version of VS I have installed is VS 2017 15.9.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please provide g++'s command line options?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've only provided the c++ standard flag (the code compiles with 11, 14 and 17). E.g:
g++ main.cpp -std=c++11

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page