Tencent / rapidjson

A fast JSON parser/generator for C++ with both SAX/DOM style API
http://rapidjson.org/
Other
14.24k stars 3.54k forks source link

Build fails on OS X 10.13: zero as null pointer constant is c++11 warning #1854

Open dmacks opened 3 years ago

dmacks commented 3 years ago

Building rapidjson-1.1.0 on OS 10.13 with xcode-10.1 (Apple LLVM version 10.0.0 clang-1000.11.45.5) fails:

[  6%] Building CXX object example/CMakeFiles/tutorial.dir/tutorial/tutorial.cpp.o
cd /tmp/rapidjson-1.1.0/build/example && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -D__STDC_FORMAT_MACROS -I/tmp/rapidjson-1.1.0/include -I/tmp/rapidjson-1.1.0/example/../include -march=native -Wall -Wextra -Werror -Wno-missing-field-initializers -std=c++11 -Werror -Wall -Wextra -Weffc++ -Wswitch-default -Wfloat-equal -Wimplicit-fallthrough -Weverything -O2 -g -DNDEBUG -o CMakeFiles/tutorial.dir/tutorial/tutorial.cpp.o -c /tmp/rapidjson-1.1.0/example/tutorial/tutorial.cpp
In file included from /tmp/rapidjson-1.1.0/example/tutorial/tutorial.cpp:4:
In file included from /tmp/rapidjson-1.1.0/include/rapidjson/document.h:20:
In file included from /tmp/rapidjson-1.1.0/include/rapidjson/reader.h:20:
/tmp/rapidjson-1.1.0/include/rapidjson/allocators.h:69:20: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
            return NULL; // standardize to returning NULL.
                   ^~~~
                   nullptr
/usr/include/sys/_types/_null.h:30:15: note: expanded from macro 'NULL'
#define NULL  __DARWIN_NULL
              ^
/usr/include/sys/_types.h:43:23: note: expanded from macro '__DARWIN_NULL'
#define __DARWIN_NULL __null
                      ^

followed by a mile of similar such messages in other source locations. Might be a new issue triggered by -std=c++11 ?

dmacks commented 3 years ago

But if I cmake with -DRAPIDJSON_BUILD_CXX11=no, build later fails differently:

[ 38%] Building CXX object example/CMakeFiles/schemavalidator.dir/schemavalidator/schemavalidator.cpp.o
cd /tmp/rapidjson-1.1.0/build/example && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -D__STDC_FORMAT_MACROS -I/tmp/rapidjson-1.1.0/include -I/tmp/rapidjson-1.1.0/example/../include -march=native -Wall -Wextra -Werror -Wno-missing-field-initializers -Werror -Wall -Wextra -Weffc++ -Wswitch-default -Wfloat-equal -Wimplicit-fallthrough -Weverything -O2 -g -DNDEBUG -o CMakeFiles/schemavalidator.dir/schemavalidator/schemavalidator.cpp.o -c /tmp/rapidjson-1.1.0/example/schemavalidator/schemavalidator.cpp
In file included from /tmp/rapidjson-1.1.0/example/schemavalidator/schemavalidator.cpp:7:
/tmp/rapidjson-1.1.0/include/rapidjson/schema.h:382:56: error: declaration shadows a typedef in 'Schema<SchemaDocumentType>' [-Werror,-Wshadow]
        typedef typename SchemaDocumentType::ValueType ValueType;
                                                       ^
/tmp/rapidjson-1.1.0/include/rapidjson/schema.h:340:52: note: previous declaration is here
    typedef typename SchemaDocumentType::ValueType ValueType;
                                                   ^
1 error generated.
fzyzcjy commented 3 years ago

have you solved this?

tinybug commented 3 years ago

add -DCMAKE_CXX_FLAGS="-Wno-shadow" with cmake will compile success, by the way, use shadow variable in source code is not a good practice. @miloyip