Build fails unless using -std=c++11
Brought to you by:
thesun
Hi, rsyncrypto 1.14 doesn't build on macOS 10.13. The errors start with:
/usr/bin/clang++ -DHAVE_CONFIG_H -I. -I/opt/local/include -pipe -Os -stdlib=libc++ -arch x86_64 -MT crypto.o -MD -MP -MF .deps/crypto.Tpo -c -o crypto.o crypto.cpp crypto.cpp:176:12: error: calling a private constructor of class 'std::__1::unique_ptr<key, std::__1::default_delete<key> >' return ret; ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/memory:2436:3: note: declared private here unique_ptr(unique_ptr&); ^ crypto.cpp:249:15: error: use of overloaded operator '==' is ambiguous (with operand types 'std::unique_ptr<key>' and 'long') if( header==NULL ) { ~~~~~~^ ~~~~ /Library/Developer/CommandLineTools/usr/include/c++/v1/memory:2900:1: note: candidate function [with _T1 = key, _D1 = std::__1::default_delete<key>] operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT ^ crypto.cpp:249:15: note: built-in candidate operator==(int, long) if( header==NULL ) { ^ crypto.cpp:249:15: note: built-in candidate operator==(unsigned __int128, long) crypto.cpp:249:15: note: built-in candidate operator==(unsigned long long, long) crypto.cpp:249:15: note: built-in candidate operator==(unsigned long, long) crypto.cpp:249:15: note: built-in candidate operator==(unsigned int, long) crypto.cpp:249:15: note: built-in candidate operator==(__int128, long) crypto.cpp:249:15: note: built-in candidate operator==(float, long)
(I omitted a zillion similar built-in candidates that follow.)
It builds fine if I add -std=c++11
to CXXFLAGS
. (This version of clang defaults to an earlier C++ standard.) If you require C++11, you should make your build system add that flag automatically.
Adding that flag automatically is not as simple as it sounds. Not all compilers require it, and it is not guaranteed that all compiler will even know how to parse
std=c++11
. As such, having the user add it if needed is the only option that makes sense.With that said, it might be a good idea to add a test to configure to make sure the compiler support C++11 features, to make the failure clearer.
Do you know which compilers don't require
-std=c++11
to compile this?That is the wrong question. The right question is do you know for sure that all compilers support that command line?
As for your other question: both clang of versions 6 and up (possibly earlier) and g++ of versions 6 and up (again, possibly earlier) do not need any special compilation flags to support C++11 features (specifically, unique_ptr). That flags was a transition period requirement.
The only reason rsyncrypto was written to make it sound like it was optional was because, when written,
std::map
was the only thing available with the standard, and that is a tree, not a hash table. To make the program more versatile, I used boost where available, and a fallback where not.When C++11 came out, I transitioned the code to use that instead, so at the time it was optional. It no longer is, as you've noticed yourself, and the configure script needs to be updated to reflect that.
I tried building on a much older system running Mac OS X 10.4 and using the MacPorts version of Apple gcc 4.2.1. When not using
-std=c++11
it failed with:Apple gcc 4.2.1 doesn't support C++11 and yet your build is trying to use
unique_ptr
which is a C++11 feature. So it seems to me that you do require C++11.