Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#15981 closed defect (invalid)

Use lambda as an argument of wxArrayString::Sort

Reported by: jbbbms Owned by:
Priority: normal Milestone:
Component: base Version: 3.0.0
Keywords: wxArrayString, Sort, c++11 lambda Cc:
Blocked By: Blocking:
Patch: no


In some circumstances, it seems incompatible with lambda. The attached file a.cpp is example exhibiting the incompatibility. In Linux wxGTK, it causes a compile-time error saying

undefined reference to `SApp::OnRun()::{lambda(wxString const&, wxString const&)#1}::_FUN(wxString const&, wxString const&)'

In Windows, it works fine, if we use -std=gnu++11 to do compiling, as it is suggested here.

There is another problem related to lambda, when working with wxArrayString::Sort. Please see the attached file b.cpp. If we use lambda to capture variables, a compile-time error will happen, no matter wxGTK or wxMSW. Below is the compile-time error in Windows.

error: no matching function for call to 'wxArrayString::Sort(SApp::OnRun()::__lambda0)'

Attachments (2)

a.cpp download (1.5 KB) - added by jbbbms 5 years ago.
b.cpp download (1.6 KB) - added by jbbbms 5 years ago.

Download all attachments as: .zip

Change History (4)

Changed 5 years ago by jbbbms

Changed 5 years ago by jbbbms

comment:1 follow-up: Changed 5 years ago by vadz

  • Resolution set to invalid
  • Status changed from new to closed

Sorry, I can't help you with these problems but this really doesn't seem to have anything to do with wx. A lambda without captures should really be convertible to a function pointer, this is C++11 and if you have troubles with it, something must be wrong with your compiler. Sort() doesn't do anything special.

comment:2 in reply to: ↑ 1 Changed 5 years ago by jbbbms

Replying to vadz:

Thanks for your reply. Indeed there seems nothing wrong with wx. I've looked into Sort() and couldn't find anything weird that might cause the compile-time error. Maybe it's as you said a problem related to the compiler. I've successfully compile the attached file a.cpp on Windows in which the GCC version is 4.8.1. On the other hand, failed to compile it on Linux where the version is 4.7.2. Thanks again for your help. Have a wonderful day.

Note: See TracTickets for help on using tickets.