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

Created on 14 Jan 2018  ·  14Comments  ·  Source: Tencent/rapidjson

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?

Most helpful comment

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 .. 

All 14 comments

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)

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

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

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() {}
     ^~~~~~

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.

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.

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

Same problem on Sailfish OS with gcc 4.8.3

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

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

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

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)

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 .. 

Same problem. mcraveiro's solution works.

Was this page helpful?
0 / 5 - 0 ratings