KhronosGroup / OpenCOLLADA

652 stars 252 forks source link

Build error using clang++ -std=c++11 #560

Open sambler opened 6 years ago

sambler commented 6 years ago

On FreeBSD using clang++ v5.0 with -std=c++11 I am getting a build error - error: no matching constructor for initialization of 'std::vector<Animation *>'

/usr/bin/c++  -DGENERATEDSAXPARSER_XMLPARSER_LIBXML -DOpenCOLLADAStreamWriter_shared_EXPORTS -DXMLPARSER_LIBXML 
-I/usr/ports/graphics/opencollada/work/OpenCOLLADA-1.6.61/COLLADAStreamWriter/include 
-I/usr/ports/graphics/opencollada/work/OpenCOLLADA-1.6.61/COLLADABaseUtils/include 
-I/usr/ports/graphics/opencollada/work/OpenCOLLADA-1.6.61/COLLADABaseUtils/include/Math 
-I/usr/ports/graphics/opencollada/work/OpenCOLLADA-1.6.61/common/libftoa/include 
-I/usr/ports/graphics/opencollada/work/OpenCOLLADA-1.6.61/common/libBuffer/include 
-I/usr/ports/graphics/opencollada/work/OpenCOLLADA-1.6.61/Externals/UTF/include -O2 -pipe  
-I//usr/local/include -fstack-protector -fno-strict-aliasing  -std=c++11  -O2 -pipe  
-I//usr/local/include -fstack-protector -fno-strict-aliasing  -std=c++11 -fPIC -MD
-MT COLLADAStreamWriter/CMakeFiles/OpenCOLLADAStreamWriter_shared.dir/src/COLLADASWLibraryAnimations.cpp.o
-MF COLLADAStreamWriter/CMakeFiles/OpenCOLLADAStreamWriter_shared.dir/src/COLLADASWLibraryAnimations.cpp.o.d -o 
COLLADAStreamWriter/CMakeFiles/OpenCOLLADAStreamWriter_shared.dir/src/COLLADASWLibraryAnimations.cpp.o -c 
/usr/ports/graphics/opencollada/work/OpenCOLLADA-1.6.61/COLLADAStreamWriter/src/COLLADASWLibraryAnimations.cpp
/usr/ports/graphics/opencollada/work/OpenCOLLADA-1.6.61/COLLADAStreamWriter/src/COLLADASWLibraryAnimations.cpp:65:79: 
error: no matching constructor for initialization of 'std::vector<Animation *>'
            : Library ( streamWriter, CSWC::CSW_ELEMENT_LIBRARY_ANIMATIONS ), mOpenAnimations ( NULL )
                                                                              ^                 ~~~~
 /usr/include/c++/v1/vector:479:40: note: candidate constructor not viable: no known conversion from 'nullptr_t' to 'const std::__1::vector<COLLADASW::Animation *, std::__1::allocator<COLLADASW::Animation *> >::allocator_type' (aka 'const std::__1::allocator<COLLADASW::Animation *>') for 1st argument
    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
                                       ^
/usr/include/c++/v1/vector:491:14: note: candidate constructor not viable: no known conversion from 'nullptr_t' to 'std::__1::vector<COLLADASW::Animation *, std::__1::allocator<COLLADASW::Animation *> >::size_type' (aka 'unsigned long') for 1st argument
    explicit vector(size_type __n);
             ^
/usr/include/c++/v1/vector:534:5: note: candidate constructor not viable: no known conversion from 'nullptr_t' to 'const std::__1::vector<COLLADASW::Animation *, std::__1::allocator<COLLADASW::Animation *> >' for 1st argument
    vector(const vector& __x);
    ^
/usr/include/c++/v1/vector:541:5: note: candidate constructor not viable: no known conversion from 'nullptr_t' to 'initializer_list<std::__1::vector<COLLADASW::Animation *, std::__1::allocator<COLLADASW::Animation *> >::value_type>' (aka 'initializer_list<COLLADASW::Animation *>') for 1st argument
    vector(initializer_list<value_type> __il);
    ^
/usr/include/c++/v1/vector:547:5: note: candidate constructor not viable: no known conversion from 'nullptr_t' to 'std::__1::vector<COLLADASW::Animation *, std::__1::allocator<COLLADASW::Animation *> >' for 1st argument
    vector(vector&& __x)
    ^

I am actually test building with pre-releases of clang v6.0 which has defaults set to using -std=c++14 but I'm getting the same error with clang 5.0 using -std=c++11 and -std=c++0x

Changing NULL to 0 compiles, but is mOpenAnimations ( 0 ) a reasonable change? or is there a better option.

jbeich commented 6 years ago

FreeBSD promotes NULL to nullptr for C++11, turning the following warning into an error. Maybe drop explicit initialization of mOpenAnimations.

Clang:

COLLADAStreamWriter/src/COLLADASWLibraryAnimations.cpp:65:97: warning:
      implicit conversion of NULL constant to 'std::__1::vector<COLLADASW::Animation *,
      std::__1::allocator<COLLADASW::Animation *> >::size_type' (aka 'unsigned long')
      [-Wnull-conversion]
  ...: Library ( streamWriter, CSWC::CSW_ELEMENT_LIBRARY_ANIMATIONS ), mOpenAnimations ( NULL )
                                                                       ~~~~~~~~~~~~~~~   ^~~~
                                                                                         0

GCC:

COLLADAStreamWriter/src/COLLADASWLibraryAnimations.cpp: In constructor 'COLLADASW::LibraryAnimations::LibraryAnimations(COLLADASW::StreamWriter*)':
COLLADAStreamWriter/src/COLLADASWLibraryAnimations.cpp:65:102: warning: passing NULL to non-pointer argument 1 of 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = COLLADASW::Animation*; _Alloc = std::allocator<COLLADASW::Animation*>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<COLLADASW::Animation*>]' [-Wconversion-null]
             : Library ( streamWriter, CSWC::CSW_ELEMENT_LIBRARY_ANIMATIONS ), mOpenAnimations ( NULL )
                                                                                                      ^
ant1 commented 6 years ago

Something like this?

--- COLLADAStreamWriter/src/COLLADASWLibraryAnimations.cpp.orig 2017-05-10 01:36:49 UTC
+++ COLLADAStreamWriter/src/COLLADASWLibraryAnimations.cpp
@@ -62,7 +62,7 @@ namespace COLLADASW

     //---------------------------------------------------------------
     LibraryAnimations::LibraryAnimations ( COLLADASW::StreamWriter * streamWriter )
-            : Library ( streamWriter, CSWC::CSW_ELEMENT_LIBRARY_ANIMATIONS ), mOpenAnimations ( NULL )
+            : Library ( streamWriter, CSWC::CSW_ELEMENT_LIBRARY_ANIMATIONS )
     {}

     //---------------------------------------------------------------
sambler commented 6 years ago

Removing mOpenAnimations ( NULL ) also fixes the build for me.