Code isn't C++ standard compliant, clang compile fails with many errors and warnings

Discuss new features and functions
Posts: 3
Joined: 2 Jan 2001

yurivict

I tried to create a port for FreeBSD, which uses primarily clang compiler, and it fails with several errors (see below). Changing compiler to gcc doesn't solve the problem there, because wx widgets are compiled with clang, and link fails due to some gcc/clang incompatibilities.

If you would like more OS to adopt FreeFileSync as a package, you need to fix clang compilation errors (and warnings too).
Please also don't use 'g++' in Makefiles. Use $CXX instead, which is a portable version of the same.

Error#1:

lib/icon_buffer.cpp:571:12: note: definition of 'Buffer::IconData' is not complete until the closing '}'
struct IconData

C++ standard doesn't allow undefined field types: 17.6.4.8: ... the effects are undefined ... if an incomplete type (3.9) is used as a template argument ...

(I personally disagree with this C++ standard requirement prohibiting incomplete types in class fields, but here isn't the right place to argue about this.)


Error#2:


In file included from ../../zen/i18n.h:10:
In file included from /usr/include/c++/v1/string:439:
In file included from /usr/include/c++/v1/algorithm:628:
/usr/include/c++/v1/memory:4283:18: error: assigning to 'std::__1::__shared_weak_count *' from incompatible type 'pointer' (aka 'std::__1::__shared_ptr_emplace<Buffer,
std::__1::allocator<Buffer> > *')
__r.__cntrl_ = __hold2.release();


Error#3:

/usr/include/c++/v1/map:1090:60: error: no viable conversion from 'iterator' (aka '__tree_iterator<value_type, __node_pointer, difference_type>') to 'iterator'
(aka '__map_iterator<typename __base::iterator>')
iterator find(const key_type& __k) {return __tree_.find(__k);}
^
lib/icon_buffer.cpp:456:28: note: in instantiation of member function 'std::__1::map<zen::Zbase<char, zen::StorageRefCountThreadSafe, AllocatorFreeStoreChecked>,
Buffer::IconData, LessFilename, std::__1::allocator<std::__1::pair<const zen::Zbase<char, zen::StorageRefCountThreadSafe, AllocatorFreeStoreChecked>,
Buffer::IconData> > >::find' requested here
auto it = iconList.find(filepath);





clang-3.4.1
FreeFileSync-6.14
User avatar
Site Admin
Posts: 7212
Joined: 9 Dec 2007

Zenju

Thanks, Error#1 is fixed by changing icon_buffer.cpp:504 like:

#ifdef __clang__ //workaround libc++ limitation for incomplete types: http://llvm.org/bugs/show_bug.cgi?id=17701
typedef std::map<Zstring, std::unique_ptr<IconData>, LessFilename> FileIconMap;
static IconData& refData(FileIconMap::iterator it) { return *(it->second); }
static std::unique_ptr<IconData> makeValueObject() { return make_unique<IconData>(); }
#else
typedef std::map<Zstring, IconData, LessFilename> FileIconMap;
IconData& refData(FileIconMap::iterator it) { return it->second; }
static IconData makeValueObject() { return IconData(); }
#endif

I assume Error#2 and Error#3 are just follow-ups?
Posts: 3
Joined: 2 Jan 2001

yurivict

Yes, this fixed it, thanks!

Now only this warning remains:

../../zen/file_io.h:65:1: warning: 'STATIC_WARNING_87903124' is deprecated [-Wdeprecated-declarations]
User avatar
Site Admin
Posts: 7212
Joined: 9 Dec 2007

Zenju

This is just a compile-time reminder for a TODO and can be ignored.