wxWidgets checkbox event lambda - events

Trying to use lambda to define event handlers for controls of the wxWidgets framework:
wxCheckBox*c=new wxCheckBox(panel,wxID_ANY,"...",wxDefaultPosition,wxDefaultSize);
c->Bind(wxEVT_CHECKBOX,[](wxCommandEvent& event){
wxMessageBox(wxT("This is the message."),wxT("This is the title"),wxICON_INFORMATION);
});
I get these error messages below, complaining about the signature? Or do I need to pass compiler flags to GCC to ensure compatibility with lambdas?
E:\bootsi\New folder\test.cpp:61:3: error: no matching function for cal
l to 'wxCheckBox::Bind(const wxEventTypeTag<wxCommandEvent>&, MyFrame::MyFrame(c
onst wxString&, const wxPoint&, const wxSize&)::__lambda0)'
});
^
E:\bootsi\New folder\test.cpp:61:3: note: candidates are:
In file included from D:/build/wxWidgets-3.0.1/include/wx/wx.h:24:0,
from E:\bootsi\New folder\test.cpp:5:
D:/build/wxWidgets-3.0.1/include/wx/event.h:3524:10: note: template<class EventT
ag, class EventArg> void wxEvtHandler::Bind(const EventTag&, void (*)(EventArg&)
, int, int, wxObject*)
void Bind(const EventTag& eventType,
^
D:/build/wxWidgets-3.0.1/include/wx/event.h:3524:10: note: template argument d
eduction/substitution failed:
E:\bootsi\New folder\test.cpp:61:3: note: mismatched types 'void (*)(
EventArg&)' and 'MyFrame::MyFrame(const wxString&, const wxPoint&, const wxSize&
)::__lambda0'
});
^
In file included from D:/build/wxWidgets-3.0.1/include/wx/wx.h:24:0,
from E:\bootsi\New folder\test.cpp:5:
D:/build/wxWidgets-3.0.1/include/wx/event.h:3550:10: note: template<class EventT
ag, class Functor> void wxEvtHandler::Bind(const EventTag&, const Functor&, int,
int, wxObject*)
void Bind(const EventTag& eventType,
^
D:/build/wxWidgets-3.0.1/include/wx/event.h:3550:10: note: template argument d
eduction/substitution failed:
E:\bootsi\New folder\test.cpp: In substitution of 'template<class Event
Tag, class Functor> void wxEvtHandler::Bind(const EventTag&, const Functor&, int
, int, wxObject*) [with EventTag = wxEventTypeTag<wxCommandEvent>; Functor = MyF
rame::MyFrame(const wxString&, const wxPoint&, const wxSize&)::__lambda0]':
E:\bootsi\New folder\test.cpp:61:3: required from here
E:\bootsi\New folder\test.cpp:61:3: error: template argument for 'templ
ate<class EventTag, class Functor> void wxEvtHandler::Bind(const EventTag&, cons
t Functor&, int, int, wxObject*)' uses local type 'MyFrame::MyFrame(const wxStri
ng&, const wxPoint&, const wxSize&)::__lambda0'
});
^
E:\bootsi\New folder\test.cpp:61:3: error: trying to instantiate 'tem
plate<class EventTag, class Functor> void wxEvtHandler::Bind(const EventTag&, co
nst Functor&, int, int, wxObject*)'
In file included from D:/build/wxWidgets-3.0.1/include/wx/wx.h:24:0,
from E:\bootsi\New folder\test.cpp:5:
D:/build/wxWidgets-3.0.1/include/wx/event.h:3579:10: note: template<class EventT
ag, class Class, class EventArg, class EventHandler> void wxEvtHandler::Bind(con
st EventTag&, void (Class::*)(EventArg&), EventHandler*, int, int, wxObject*)
void Bind(const EventTag &eventType,
^
D:/build/wxWidgets-3.0.1/include/wx/event.h:3579:10: note: template argument d
eduction/substitution failed:
E:\bootsi\New folder\test.cpp:61:3: note: mismatched types 'void (Cla
ss::*)(EventArg&)' and 'MyFrame::MyFrame(const wxString&, const wxPoint&, const
wxSize&)::__lambda0'
});
^
CMakeFiles\test.dir\build.make:54: recipe for target 'CMakeFiles/FreshS
ettings.dir/test.cpp.obj' failed
mingw32-make[3]: *** [CMakeFiles/test.dir/test.cpp.obj] Error
1
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/test.dir/all' fa
iled
mingw32-make[2]: *** [CMakeFiles/test.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/test.dir/rule' f
ailed
mingw32-make[1]: *** [CMakeFiles/test.dir/rule] Error 2
Makefile:109: recipe for target 'test' failed
mingw32-make: *** [test] Error 2
Press any key to continue . . .

You need to build (both the library and your own code) with -std=c++11 g++ option for lambdas to work. You also need a version of g++ with C++11 support, of course, so at least 4.7.

Related

error: "Protobuf requires at least C++11." with clang version already on version 13.1

I am using mac M1 chip.
i am doing bundle install to install the dependency of my service.
One of our ruby package is using protobuf, so i am getting below error while installing package natively.
Clang version installed is already 13+.
My ruby version is 2.6.6.
i tried with clang version below 11, but getting same error.
Anyone can help what is going wrong here?
/opt/homebrew/include/google/protobuf/stubs/port.h:123:2: error: "Protobuf requires at least C++11."
#error "Protobuf requires at least C++11."
^
/opt/homebrew/include/google/protobuf/stubs/port.h:129:26: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using ConstStringParam = const std::string &;
^
/opt/homebrew/include/google/protobuf/stubs/port.h:145:39: error: expected '(' for function-style cast or type construction
static const int64 kint64max = int64_t{0x7FFFFFFFFFFFFFFF};
~~~~~~~^
/opt/homebrew/include/google/protobuf/stubs/port.h:148:42: error: expected '(' for function-style cast or type construction
static const uint64 kuint64max = uint64_t{0xFFFFFFFFFFFFFFFFu};
~~~~~~~~^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:9:
In file included from /opt/homebrew/include/google/protobuf/stubs/common.h:49:
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:165:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using traits_type = std::char_traits<char>;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:166:22: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using value_type = char;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:167:19: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using pointer = char*;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:168:25: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using const_pointer = const char*;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:169:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using reference = char&;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:170:27: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using const_reference = const char&;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:171:26: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using const_iterator = const char*;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:172:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using iterator = const_iterator;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:173:34: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:174:28: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using reverse_iterator = const_reverse_iterator;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:175:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using size_type = size_t;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:176:27: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using difference_type = std::ptrdiff_t;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:182:10: error: unknown type name 'constexpr'
static constexpr size_type kMaxSize =
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:182:29: error: expected ';' at end of declaration list
static constexpr size_type kMaxSize =
^
;
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:280:3: warning: explicit conversion functions are a C++11 extension [-Wc++11-extensions]
explicit operator std::string() const { return ToString(); }
^~~~~~~~
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:187:39: error: use of undeclared identifier 'kMaxSize'
if (PROTOBUF_PREDICT_FALSE(size > kMaxSize)) {
^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:9:
/opt/homebrew/include/google/protobuf/stubs/common.h:166:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto volatile unused = &var;
^
/opt/homebrew/include/google/protobuf/stubs/common.h:179:36: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
const char* what() const throw() override;
^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
/Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:17:2: error: This file was generated by an older version of protoc which is
#error This file was generated by an older version of protoc which is
^
/Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:18:2: error: incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
^
/Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:19:2: error: regenerate this file with a newer version of protoc.
#error regenerate this file with a newer version of protoc.
^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:22:
In file included from /opt/homebrew/include/google/protobuf/generated_message_util.h:49:
In file included from /opt/homebrew/include/google/protobuf/any.h:37:
In file included from /opt/homebrew/include/google/protobuf/arenastring.h:38:
In file included from /opt/homebrew/include/google/protobuf/stubs/logging.h:36:
/opt/homebrew/include/google/protobuf/stubs/status.h:46:6: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class StatusCode : int {
^
/opt/homebrew/include/google/protobuf/stubs/status.h:81:43: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]
bool ok() const { return error_code_ == StatusCode::kOk; }
^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:22:
In file included from /opt/homebrew/include/google/protobuf/generated_message_util.h:49:
In file included from /opt/homebrew/include/google/protobuf/any.h:37:
In file included from /opt/homebrew/include/google/protobuf/arenastring.h:40:
In file included from /opt/homebrew/include/google/protobuf/arena.h:55:
/opt/homebrew/include/google/protobuf/arena_impl.h:54:8: error: unknown type name 'constexpr'
inline constexpr size_t AlignUpTo8(size_t n) {
^
/opt/homebrew/include/google/protobuf/arena_impl.h:54:1: warning: inline variables are a C++17 extension [-Wc++17-extensions]
inline constexpr size_t AlignUpTo8(size_t n) {
^
/opt/homebrew/include/google/protobuf/arena_impl.h:54:24: error: expected ';' after top level declarator
inline constexpr size_t AlignUpTo8(size_t n) {
^
;
/opt/homebrew/include/google/protobuf/arena_impl.h:90:30: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions]
~ArenaMetricsCollector() = default;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:95:10: error: unknown type name 'constexpr'
static constexpr size_t kDefaultStartBlockSize = 256;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:95:26: error: expected ';' at end of declaration list
static constexpr size_t kDefaultStartBlockSize = 256;
^
;
/opt/homebrew/include/google/protobuf/arena_impl.h:96:10: error: unknown type name 'constexpr'
static constexpr size_t kDefaultMaxBlockSize = 8192;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:96:26: error: expected ';' at end of declaration list
static constexpr size_t kDefaultMaxBlockSize = 8192;
^
;
/opt/homebrew/include/google/protobuf/arena_impl.h:98:3: error: unknown type name 'size_t'
size_t start_block_size = kDefaultStartBlockSize;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:98:27: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
size_t start_block_size = kDefaultStartBlockSize;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:99:3: error: unknown type name 'size_t'
size_t max_block_size = kDefaultMaxBlockSize;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:99:25: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
size_t max_block_size = kDefaultMaxBlockSize;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:100:24: error: unknown type name 'size_t'
void* (*block_alloc)(size_t) = nullptr;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:100:32: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
void* (*block_alloc)(size_t) = nullptr;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:101:32: error: unknown type name 'size_t'
void (*block_dealloc)(void*, size_t) = nullptr;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:101:40: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
void (*block_dealloc)(void*, size_t) = nullptr;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:102:44: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
ArenaMetricsCollector* metrics_collector = nullptr;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
25 warnings and 20 errors generated.
make[2]: *** [src/CMakeFiles/Protobuf.dir/one_quota.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/Protobuf.dir/all] Error 2
make: *** [all] Error 2

c++ - is it possible to create an optional promise?

consider the following code:
#include <future>
#include <boost/optional.hpp>
struct S {
std::promise<int> p;
};
void f() {
boost::optional<S> o = std::move(S());
}
it fails to compile because somewhere deep inside boost::optional implementation it tries to use the copy constructor of S.
is there some way to overcome this and move the promise without copying it?
I tried to explicitly add a move constructor to S
S(S&& s): p(std::move(s.p)) {}
S() = default;
to no avail.
compiler error message:
In file included from /usr/include/boost/optional.hpp:15:0,
from /tmp/iotpromise.cpp:2:
/usr/include/boost/optional/optional.hpp: In instantiation of ‘void boost::optional_detail::optional_base<T>::construct(boost::optional_detail::optional_base<T>::argument_type) [with T = S; boost::optional_detail::optional_base<T>::argument_type = const S&]’:
/usr/include/boost/optional/optional.hpp:230:20: required from ‘boost::optional_detail::optional_base<T>::optional_base(boost::optional_detail::optional_base<T>::argument_type) [with T = S; boost::optional_detail::optional_base<T>::argument_type = const S&]’
/usr/include/boost/optional/optional.hpp:526:46: required from ‘boost::optional<T>::optional(boost::optional<T>::argument_type) [with T = S; boost::optional<T>::argument_type = const S&]’
/tmp/iotpromise.cpp:9:39: required from here
/usr/include/boost/optional/optional.hpp:346:8: error: use of deleted function ‘S::S(const S&)’
new (m_storage.address()) internal_type(val) ;
^
/tmp/iotpromise.cpp:4:8: note: ‘S::S(const S&)’ is implicitly deleted because the default definition would be ill-formed:
struct S {
^
/tmp/iotpromise.cpp:4:8: error: use of deleted function ‘std::promise<_Res>::promise(const std::promise<_Res>&) [with _Res = int]’
In file included from /tmp/iotpromise.cpp:1:0:
/usr/include/c++/4.9/future:977:7: note: declared here
promise(const promise&) = delete;
^
Using Boost 1.55.0, GCC 6.3

Unable to compare std::chrono::duration with zero

In a template class I am working on, I want to check a precondition that a std::chrono::duration is positive, but my compiler complains that it can not instantiate the needed operator< template.
Here is a minimal example (not my original container) of the problem:
#include <chrono>
#include <cassert>
#undef NDEBUG
template< typename VALUE >
class Container final
{
public:
using Interval = std::chrono::duration< unsigned int >;
Container(const Interval interval_):
interval(interval_),
value(0)
{
assert(Interval::zero < interval_);
}
private:
Interval interval;
VALUE value;
};
template class Container< unsigned int >;
The compiler complains about the assert statement, thus:
In file included from /usr/include/c++/6/cassert:44:0,
from main.cpp:2:
main.cpp: In constructor ‘Container<VALUE>::Container(Container<VALUE>::Interval)’:
main.cpp:15:29: error: no match for ‘operator<’ (operand types are ‘std::chrono::duration<unsigned int>()’ and ‘const Interval {aka const std::chrono::duration<unsigned int>}’)
assert(Interval::zero < interval_);
~~~~~~~~~~~~~~~^~~
In file included from main.cpp:1:0:
/usr/include/c++/6/chrono:668:7: note: candidate: template<class _Clock, class _Dur1, class _Dur2> constexpr bool std::chrono::operator<(const std::chrono::time_point<_Clock, _Duration1>&, const std::chrono::time_point<_Clock, _Duration2>&)
operator<(const time_point<_Clock, _Dur1>& __lhs,
^~~~~~~~
/usr/include/c++/6/chrono:668:7: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/cassert:44:0,
from main.cpp:2:
main.cpp:15:31: note: mismatched types ‘const std::chrono::time_point<_Clock, _Duration1>’ and ‘std::chrono::duration<unsigned int>()’
assert(Interval::zero < interval_);
^
In file included from main.cpp:1:0:
/usr/include/c++/6/chrono:489:7: note: candidate: template<class _Rep1, class _Period1, class _Rep2, class _Period2> constexpr bool std::chrono::operator<(const std::chrono::duration<_Rep1, _Period1>&, const std::chrono::duration<_Rep2, _Period2>&)
operator<(const duration<_Rep1, _Period1>& __lhs,
^~~~~~~~
/usr/include/c++/6/chrono:489:7: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/6/cassert:44:0,
from main.cpp:2:
main.cpp:15:31: note: mismatched types ‘const std::chrono::duration<_Rep1, _Period1>’ and ‘std::chrono::duration<unsigned int>()’
assert(Interval::zero < interval_);
What have I done wrong?
Or is this a compiler bug? My compiler is g++ (Debian 6.3.0-18+deb9u1) 6.3.0 2017051, on Debian 6.
Try with Interval::zero(). Interval::zero is a function, so you are comparing a duration with a function.
As a side note, I would suggest to make your Interval argument in the constructor a template, so that you can accept other duragion scales (seconds, ms, us, etc.)
template < typename Interval2 >
explicit Container(const Interval2 interval_):
interval(interval_),
value(0)
{
assert(Interval2::zero() < interval_);
}
The std::chrono::duration constructor will adapt the tick count transparently, following both Period parameter types.

Confusing clang error attempting to instantiate std::thread with a pointer

While looking at Thread and interfaces C++, I noticed something a little strange with my Clang.
I have c++ --version output of
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
Compiling the following
#include <thread>
class Foo {
public:
void operator()() { }
};
int main() {
Foo *foo = new Foo();
std::thread t(foo);
t.join();
delete foo;
}
with c++ thread.cpp yields the following sensible error:
In file included from thread.cpp:1:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:369:5: error: called object type 'Foo *' is not a function or
function pointer
(*__p)();
^~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:377:42: note: in instantiation of function template
specialization 'std::__1::__thread_proxy<Foo *>' requested here
int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Fp>, __p.get());
^
thread.cpp:10:17: note: in instantiation of function template specialization 'std::__1::thread::thread<Foo *>' requested here
std::thread t(foo);
^
1 error generated.
Total sense - Foo * isn't a function pointer.
But, compiling it with c++ -std=c++11 thread.cpp gives this cryptic error:
In file included from thread.cpp:1:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:332:5: error: attempt to use a deleted function
__invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:342:5: note: in instantiation of function template
specialization 'std::__1::__thread_execute<Foo *>' requested here
__thread_execute(*__p, _Index());
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:354:42: note: in instantiation of function template
specialization 'std::__1::__thread_proxy<std::__1::tuple<Foo *> >' requested here
int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Gp>, __p.get());
^
thread.cpp:10:17: note: in instantiation of function template specialization 'std::__1::thread::thread<Foo *&, void>' requested here
std::thread t(foo);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:1027:5: note: '~__nat' has been explicitly marked
deleted here
~__nat() = delete;
^
1 error generated.
What's causing this weird error message about a deleted destructor? Should I consider it a bug in Clang to have such an odd message?
Your actual error message is the same in the two cases: whatever template is used to implement std::thread, it cannot be specialized for Foo*.
~__nat() = delete; is only a random difference between the old and new standard, one of the uninteresting things that fail because of the type error.

Unable to build with Qt on Snow Leopard

I installed Qt and tried to build a template project (Qt4 Gui Application) in QtCreator. I can't figure out why I am getting these errors.
Running build steps for project SourceControl...
Configuration unchanged, skipping QMake step.
Starting: /usr/bin/make -w
make: Entering directory `/Users/jason/SourceControl'
g++ -c -pipe -g -gdwarf-2 -Wall -W -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Qt4.5/mkspecs/macx-g++ -I. -I/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/usr/include/QtCore -I/Library/Frameworks/QtNetwork.framework/Versions/4/Headers -I/usr/include/QtNetwork -I/Library/Frameworks/QtGui.framework/Versions/4/Headers -I/usr/include/QtGui -I/usr/include -I. -I. -F/Library/Frameworks -o main.o main.cpp
In file included from /Library/Frameworks/QtCore.framework/Headers/qnamespace.h:45,
from /Library/Frameworks/QtCore.framework/Headers/qobjectdefs.h:45,
from /Library/Frameworks/QtCore.framework/Headers/qobject.h:47,
from /Library/Frameworks/QtCore.framework/Headers/qcoreapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/qapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/QApplication:1,
from main.cpp:1:
/Library/Frameworks/QtCore.framework/Headers/qglobal.h:297:34: error: AvailabilityMacros.h: No such file or directory
In file included from /Library/Frameworks/QtCore.framework/Headers/qstring.h:46,
from /Library/Frameworks/QtCore.framework/Headers/qobject.h:48,
from /Library/Frameworks/QtCore.framework/Headers/qcoreapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/qapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/QApplication:1,
from main.cpp:1:
/Library/Frameworks/QtCore.framework/Headers/qbytearray.h:48:20: error: string.h: No such file or directory
In file included from /Library/Frameworks/QtCore.framework/Headers/qobject.h:48,
from /Library/Frameworks/QtCore.framework/Headers/qcoreapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/qapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/QApplication:1,
from main.cpp:1:
/Library/Frameworks/QtCore.framework/Headers/qstring.h:60:22: error: string: No such file or directory
In file included from /Library/Frameworks/QtCore.framework/Headers/qobject.h:50,
from /Library/Frameworks/QtCore.framework/Headers/qcoreapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/qapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/QApplication:1,
from main.cpp:1:
/Library/Frameworks/QtCore.framework/Headers/qlist.h:50:20: error: iterator: No such file or directory
/Library/Frameworks/QtCore.framework/Headers/qlist.h:51:16: error: list: No such file or directory
/Library/Frameworks/QtCore.framework/Headers/qlist.h:54:15: error: new: No such file or directory
In file included from /Library/Frameworks/QtGui.framework/Headers/qbrush.h:47,
from /Library/Frameworks/QtGui.framework/Headers/qpalette.h:47,
from /Library/Frameworks/QtGui.framework/Headers/qwidget.h:48,
from /Library/Frameworks/QtGui.framework/Headers/qmainwindow.h:45,
from /Library/Frameworks/QtGui.framework/Headers/QMainWindow:1,
from mainwindow.h:4,
from main.cpp:2:
/Library/Frameworks/QtCore.framework/Headers/qvector.h:52:18: error: vector: No such file or directory
/Library/Frameworks/QtCore.framework/Headers/qvector.h:54:20: error: stdlib.h: No such file or directory
In file included from /Library/Frameworks/QtCore.framework/Headers/qstring.h:46,
from /Library/Frameworks/QtCore.framework/Headers/qobject.h:48,
from /Library/Frameworks/QtCore.framework/Headers/qcoreapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/qapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/QApplication:1,
from main.cpp:1:
/Library/Frameworks/QtCore.framework/Headers/qbytearray.h: In function 'uint qstrlen(const char*)':
/Library/Frameworks/QtCore.framework/Headers/qbytearray.h:68: error: 'strlen' was not declared in this scope
/Library/Frameworks/QtCore.framework/Headers/qbytearray.h: In function 'int qstrncmp(const char*, const char*, uint)':
/Library/Frameworks/QtCore.framework/Headers/qbytearray.h:91: error: 'strncmp' was not declared in this scope
/Library/Frameworks/QtCore.framework/Headers/qbytearray.h: In function 'bool operator==(const QByteArray&, const QByteArray&)':
/Library/Frameworks/QtCore.framework/Headers/qbytearray.h:502: error: 'memcmp' was not declared in this scope
In file included from /Library/Frameworks/QtCore.framework/Headers/qobject.h:48,
from /Library/Frameworks/QtCore.framework/Headers/qcoreapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/qapplication.h:45,
from /Library/Frameworks/QtGui.framework/Headers/QApplication:1,
from main.cpp:1:
/Library/Frameworks/QtCore.framework/Headers/qstring.h: At global scope:
/Library/Frameworks/QtCore.framework/Headers/qstring.h:65: error: expected initializer before ' QList::fromStdList()':
/Library/Frameworks/QtCore.framework/Headers/qlist.h:316: error: 'list' was not declared in this scope
/Library/Frameworks/QtCore.framework/Headers/qlist.h:316: error: 'back_inserter' is not a member of 'std'
In file included from /Library/Frameworks/QtGui.framework/Headers/qbrush.h:47,
from /Library/Frameworks/QtGui.framework/Headers/qpalette.h:47,
from /Library/Frameworks/QtGui.framework/Headers/qwidget.h:48,
from /Library/Frameworks/QtGui.framework/Headers/qmainwindow.h:45,
from /Library/Frameworks/QtGui.framework/Headers/QMainWindow:1,
from mainwindow.h:4,
from main.cpp:2:
/Library/Frameworks/QtCore.framework/Headers/qvector.h: At global scope:
/Library/Frameworks/QtCore.framework/Headers/qvector.h:293: error: expected unqualified-id before ' QVector::fromStdVector()':
/Library/Frameworks/QtCore.framework/Headers/qvector.h:294: error: 'vector' was not declared in this scope
/Library/Frameworks/QtCore.framework/Headers/qvector.h:294: error: 'back_inserter' is not a member of 'std'
/Library/Frameworks/QtCore.framework/Headers/qvector.h: In constructor 'QVector::QVector(int) [with T = QPoint]':
/Library/Frameworks/QtGui.framework/Headers/qpolygon.h:93: instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qvector.h:397: error: no matching function for call to 'operator new(long unsigned int, QPoint*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h: In constructor 'QVector::QVector(int) [with T = QPointF]':
/Library/Frameworks/QtGui.framework/Headers/qpolygon.h:152: instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qvector.h:397: error: no matching function for call to 'operator new(long unsigned int, QPointF*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qlist.h: In member function 'void QList::node_construct(QList::Node*, const T&) [with T = QString]':
/Library/Frameworks/QtCore.framework/Headers/qlist.h:426: instantiated from 'void QList::append(const T&) [with T = QString]'
/Library/Frameworks/QtCore.framework/Headers/qstringlist.h:70: instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qlist.h:341: error: no matching function for call to 'operator new(long unsigned int, QList::Node*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qlist.h: In member function 'void QList::node_copy(QList::Node*, QList::Node*, QList::Node*) [with T = QString]':
/Library/Frameworks/QtCore.framework/Headers/qlist.h:618: instantiated from 'QList& QList::operator+=(const QList&) [with T = QString]'
/Library/Frameworks/QtCore.framework/Headers/qstringlist.h:85: instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qlist.h:360: error: no matching function for call to 'operator new(long unsigned int, QList::Node*)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h: In member function 'void QVector::realloc(int, int) [with T = QPoint]':
/Library/Frameworks/QtCore.framework/Headers/qvector.h:315: instantiated from 'void QVector::detach_helper() [with T = QPoint]'
/Library/Frameworks/QtCore.framework/Headers/qvector.h:113: instantiated from 'QVector::QVector(const QVector&) [with T = QPoint]'
/Library/Frameworks/QtGui.framework/Headers/qpolygon.h:66: instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qvector.h:444: error: no matching function for call to 'operator new(long unsigned int, QPoint*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h:484: error: no matching function for call to 'operator new(long unsigned int, QPoint*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h:491: error: no matching function for call to 'operator new(long unsigned int, QPoint*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h: In member function 'void QVector::realloc(int, int) [with T = QPointF]':
/Library/Frameworks/QtCore.framework/Headers/qvector.h:315: instantiated from 'void QVector::detach_helper() [with T = QPointF]'
/Library/Frameworks/QtCore.framework/Headers/qvector.h:113: instantiated from 'QVector::QVector(const QVector&) [with T = QPointF]'
/Library/Frameworks/QtGui.framework/Headers/qpolygon.h:131: instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qvector.h:444: error: no matching function for call to 'operator new(long unsigned int, QPointF*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h:484: error: no matching function for call to 'operator new(long unsigned int, QPointF*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h:491: error: no matching function for call to 'operator new(long unsigned int, QPointF*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h: In member function 'void QVector::realloc(int, int) [with T = QPainterPath::Element]':
/Library/Frameworks/QtCore.framework/Headers/qvector.h:315: instantiated from 'void QVector::detach_helper() [with T = QPainterPath::Element]'
/Library/Frameworks/QtCore.framework/Headers/qvector.h:129: instantiated from 'void QVector::detach() [with T = QPainterPath::Element]'
/Library/Frameworks/QtCore.framework/Headers/qvector.h:228: instantiated from 'T* QVector::begin() [with T = QPainterPath::Element]'
/Library/Frameworks/QtCore.framework/Headers/qvector.h:241: instantiated from 'T& QVector::first() [with T = QPainterPath::Element]'
/Library/Frameworks/QtGui.framework/Headers/qpainterpath.h:370: instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qvector.h:444: error: no matching function for call to 'operator new(long unsigned int, QPainterPath::Element*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h:315: instantiated from 'void QVector::detach_helper() [with T = QPainterPath::Element]'
/Library/Frameworks/QtCore.framework/Headers/qvector.h:129: instantiated from 'void QVector::detach() [with T = QPainterPath::Element]'
/Library/Frameworks/QtCore.framework/Headers/qvector.h:228: instantiated from 'T* QVector::begin() [with T = QPainterPath::Element]'
/Library/Frameworks/QtCore.framework/Headers/qvector.h:241: instantiated from 'T& QVector::first() [with T = QPainterPath::Element]'
/Library/Frameworks/QtGui.framework/Headers/qpainterpath.h:370: instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qvector.h:484: error: no matching function for call to 'operator new(long unsigned int, QPainterPath::Element*&)'
:0: note: candidates are: void* operator new(long unsigned int)
/Library/Frameworks/QtCore.framework/Headers/qvector.h:491: error: no matching function for call to 'operator new(long unsigned int, QPainterPath::Element*&)'
:0: note: candidates are: void* operator new(long unsigned int)
make: *** [main.o] Error 1
make: Leaving directory `/Users/jason/SourceControl'
Exited with code 2.
Error while building project SourceControl
When executing build step 'Make'
I'm not sure but I guess you should focus on the first error where it says it can't find AvailabilityMacros.h. I think that should be in /usr/include but I'm guessing it probably isn't since your compile line clearly shows that as one of the include paths.
If it's not there you could try to find out where it is by using find on the command line eg.
find /usr -name AvailabilityMacros.h
or whatever GUI methods are available on the Mac ( you can tell I'm not that familiar with MacOS :) ). BTW if the above find command yields nothing then you can widen the search from /usr to /.
In response to your posting of the find results:
Are you trying to build your application against the MacOSX10.5.sdk? If not then I don't think that's the version you want. If you are using the 10.5 SDK then you need to set the QMAKE_MAC_SDK qmake variable to /Developer/SDKs/MacOSX10.5.sdk. You can either do this in the project file or set it as an additional argument to qmake in Projects->Build steps.
Thanks, Troubadour. I was able to solve the problem by adding the following line to my project's .pro file:
QMAKE_MAC_SDK = /Developer/SDKs/MacOSX10.5.sdk
I would prefer to build against the Mac OS X 10.6 SDK but there is no such directory in /Developer/SDKs. If you know where I can find the 10.6 SDK please let me know.
EDIT: After updating to the latest version of Xcode, I was able to remove the line indicated above from my project's .pro file and compile successfully.

Resources