rapidjson icon indicating copy to clipboard operation
rapidjson copied to clipboard

-Werror=effc++ build errors in archiver.h

Open antaljanosbenjamin opened this issue 8 years ago • 14 comments

Hi! I'm trying to build with GNU G++ 5.4.0 but I get these errors:

[ 19%] Building CXX object example/CMakeFiles/archivertest.dir/archiver/archiver.cpp.o In file included from /home/test/rapidjsonbuild/rapidjson/example/archiver/archiver.cpp:1:0: /home/test/rapidjsonbuild/rapidjson/example/archiver/archiver.h:56:7: error: ‘class JsonReader’ has pointer data members [-Werror=effc++] class JsonReader { ^ /home/test/rapidjsonbuild/rapidjson/example/archiver/archiver.h:56:7: error: but does not override ‘JsonReader(const JsonReader&)’ [-Werror=effc++] /home/test/rapidjsonbuild/rapidjson/example/archiver/archiver.h:56:7: error: or ‘operator=(const JsonReader&)’ [-Werror=effc++] /home/test/rapidjsonbuild/rapidjson/example/archiver/archiver.h:100:7: error: ‘class JsonWriter’ has pointer data members [-Werror=effc++] class JsonWriter { ^ /home/test/rapidjsonbuild/rapidjson/example/archiver/archiver.h:100:7: error: but does not override ‘JsonWriter(const JsonWriter&)’ [-Werror=effc++] /home/test/rapidjsonbuild/rapidjson/example/archiver/archiver.h:100:7: error: or ‘operator=(const JsonWriter&)’ [-Werror=effc++] cc1plus: all warnings being treated as errors example/CMakeFiles/archivertest.dir/build.make:62: recipe for target 'example/CMakeFiles/archivertest.dir/archiver/archiver.cpp.o' failed make[2]: *** [example/CMakeFiles/archivertest.dir/archiver/archiver.cpp.o] Error 1 CMakeFiles/Makefile2:1326: recipe for target 'example/CMakeFiles/archivertest.dir/all' failed make[1]: *** [example/CMakeFiles/archivertest.dir/all] Error 2 Makefile:138: recipe for target 'all' failed make: *** [all] Error 2

The full log can be found here.

Did I do something wrong?

antaljanosbenjamin avatar Jan 14 '18 00:01 antaljanosbenjamin

Got the same error on gcc5. I think it could be caused by the differences of the policy about default constructor between gcc5 and newer version. (NO RESEARCH)

Oyami-Srk avatar Jan 14 '18 16:01 Oyami-Srk

I have the same problem on Debian stretch with gcc version 6.3.0 20170516. Running bisect shows that this commit broke it:

commit f2a28ee4720f34efae516c04eccb97e6820644b2
Date:   Wed Dec 13 21:53:18 2017 +0800
     Add archiver example

Which is obviously the commit which added the problematic files for the first time

Andy1978 avatar Jan 15 '18 07:01 Andy1978

@antaljanosbenjamin Please confirm if the last commit solved this, and close this if so. Thank you.

miloyip avatar Jan 17 '18 02:01 miloyip

I see similar errors in archivertest.cpp (with gcc 7.2.0):

/rapidjson-fc7cda7/example/archiver/archivertest.cpp: In constructor 'Student::Student()':
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:8:8: error: 'Student::name' should be initialized in the member initialization list [-Werror=effc++]
 struct Student {
        ^~~~~~~
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:8:8: error: 'Student::age' should be initialized in the member initialization list [-Werror=effc++]
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:8:8: error: 'Student::height' should be initialized in the member initialization list [-Werror=effc++]
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:8:8: error: 'Student::canSwim' should be initialized in the member initialization list [-Werror=effc++]
/rapidjson-fc7cda7/example/archiver/archivertest.cpp: In function 'void test1()':
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:44:17: note: synthesized method 'Student::Student()' first required here
         Student s;
                 ^
/rapidjson-fc7cda7/example/archiver/archivertest.cpp: In constructor 'Group::Group()':
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:56:8: error: 'Group::groupName' should be initialized in the member initialization list [-Werror=effc++]
 struct Group {
        ^~~~~
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:56:8: error: 'Group::students' should be initialized in the member initialization list [-Werror=effc++]
/rapidjson-fc7cda7/example/archiver/archivertest.cpp: In function 'void test2()':
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:92:15: note: synthesized method 'Group::Group()' first required here
         Group g;
               ^
/rapidjson-fc7cda7/example/archiver/archivertest.cpp: In constructor 'Shape::Shape()':
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:127:5: error: 'Shape::x_' should be initialized in the member initialization list [-Werror=effc++]
     Shape() {}
     ^~~~~
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:127:5: error: 'Shape::y_' should be initialized in the member initialization list [-Werror=effc++]
/rapidjson-fc7cda7/example/archiver/archivertest.cpp: In constructor 'Circle::Circle()':
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:145:5: error: 'Circle::radius_' should be initialized in the member initialization list [-Werror=effc++]
     Circle() {}
     ^~~~~~
/rapidjson-fc7cda7/example/archiver/archivertest.cpp: In constructor 'Box::Box()':
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:171:5: error: 'Box::width_' should be initialized in the member initialization list [-Werror=effc++]
     Box() {}
     ^~~
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:171:5: error: 'Box::height_' should be initialized in the member initialization list [-Werror=effc++]
/rapidjson-fc7cda7/example/archiver/archivertest.cpp: In constructor 'Canvas::Canvas()':
/rapidjson-fc7cda7/example/archiver/archivertest.cpp:198:5: error: 'Canvas::shapes_' should be initialized in the member initialization list [-Werror=effc++]
     Canvas() {}
     ^~~~~~

bjowi avatar Jan 17 '18 10:01 bjowi

Shouldn't -Weffc++ be removed instead? I've read that there are many related bugreports in the bugreport and many of the advices are outdated.

Andy1978 avatar Jan 17 '18 10:01 Andy1978

However, some users enable that flag in their projects and complains that RapidJSON generates the warnings. It is quite trouble to battle in warning war, yet I have been trying to fix the code, or to suppress part of code with #pragma.

miloyip avatar Jan 18 '18 02:01 miloyip

"should be initialized in the member initialization list" is actually quite useful.

Bu11etmagnet avatar Jan 18 '18 09:01 Bu11etmagnet

Same problem on Sailfish OS with gcc 4.8.3

Nikolay0054 avatar Jan 18 '18 17:01 Nikolay0054

Thanks for a great library. I have the same problem on Alpine, with:

$ g++ --version
g++ (Alpine 6.4.0) 6.4.0

Is there any workaround that one can use for the moment? e.g. set CXX FLAGS perhaps.

Cheers

mcraveiro avatar Jan 23 '18 16:01 mcraveiro

@miloyip Sorry for the late answer and thanks for the fix, I can compile now! Keep up the good work!

antaljanosbenjamin avatar Jan 23 '18 20:01 antaljanosbenjamin

Hi @antaljanosbenjamin,

what target are you using to build the library? I don't really require the tests so maybe I can use the same.

Cheers

mcraveiro avatar Jan 24 '18 11:01 mcraveiro

Actually, I now see the CMake options, lemme try these.

option(RAPIDJSON_BUILD_DOC "Build rapidjson documentation." ON)
option(RAPIDJSON_BUILD_EXAMPLES "Build rapidjson examples." ON)
option(RAPIDJSON_BUILD_TESTS "Build rapidjson perftests and unittests." ON)
option(RAPIDJSON_BUILD_THIRDPARTY_GTEST
    "Use gtest installation in `thirdparty/gtest` by default if available" OFF)

mcraveiro avatar Jan 24 '18 11:01 mcraveiro

Yep, this solved my problem. Thanks. If anyone has a similar problem, I did:

cmake  -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_INSTALL_PREFIX=/usr \
          -DRAPIDJSON_BUILD_DOC=off -DRAPIDJSON_BUILD_EXAMPLES=off \
          -DRAPIDJSON_BUILD_TESTS=off -DRAPIDJSON_BUILD_THIRDPARTY_GTEST=off .. 

mcraveiro avatar Jan 24 '18 11:01 mcraveiro

Same problem. mcraveiro's solution works.

rbaxter1 avatar Jan 31 '18 14:01 rbaxter1