Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NLohmann doesn't compile when enabling strict warning policies #1224

Closed
Wittmaxi opened this issue Sep 3, 2018 · 7 comments
Closed

NLohmann doesn't compile when enabling strict warning policies #1224

Wittmaxi opened this issue Sep 3, 2018 · 7 comments
Assignees
Labels
confirmed solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@Wittmaxi
Copy link

Wittmaxi commented Sep 3, 2018

  • What is the issue you have?
    Project including nlohmann doesn't compile with strict warning options:
g++ *.cpp -g -o test -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Werror -Wno-unused
  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
#include "json.hpp"

int main();
  • What is the expected behavior?

Clean compile, no warnings

  • And what is the actual behavior instead?
    Getting following warnings:
$ g++ *.cpp -g -o test -pedantic -Wall -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wswitch-default -Wundef -Werror -Wno-unused


In file included from main.cpp:1:0:
json.hpp:231:33: error: all member functions in class ‘nlohmann::detail::has_mapped_type<T>’ are private [-Werror=ctor-dtor-privacy]
     template<typename T> struct has_##type {                                  \
                                 ^
json.hpp:374:1: note: in expansion of macro ‘NLOHMANN_JSON_HAS_HELPER’
 NLOHMANN_JSON_HAS_HELPER(mapped_type);
 ^~~~~~~~~~~~~~~~~~~~~~~~
json.hpp:231:33: error: all member functions in class ‘nlohmann::detail::has_key_type<T>’ are private [-Werror=ctor-dtor-privacy]
     template<typename T> struct has_##type {                                  \
                                 ^
json.hpp:375:1: note: in expansion of macro ‘NLOHMANN_JSON_HAS_HELPER’
 NLOHMANN_JSON_HAS_HELPER(key_type);
 ^~~~~~~~~~~~~~~~~~~~~~~~
json.hpp:231:33: error: all member functions in class ‘nlohmann::detail::has_value_type<T>’ are private [-Werror=ctor-dtor-privacy]
     template<typename T> struct has_##type {                                  \
                                 ^
json.hpp:376:1: note: in expansion of macro ‘NLOHMANN_JSON_HAS_HELPER’
 NLOHMANN_JSON_HAS_HELPER(value_type);
 ^~~~~~~~~~~~~~~~~~~~~~~~
json.hpp:231:33: error: all member functions in class ‘nlohmann::detail::has_iterator<T>’ are private [-Werror=ctor-dtor-privacy]
     template<typename T> struct has_##type {                                  \
                                 ^
json.hpp:377:1: note: in expansion of macro ‘NLOHMANN_JSON_HAS_HELPER’
 NLOHMANN_JSON_HAS_HELPER(iterator);
 ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from main.cpp:1:0:
json.hpp:471:8: error: all member functions in class ‘nlohmann::detail::has_from_json<BasicJsonType, T>’ are private [-Werror=ctor-dtor-privacy]
 struct has_from_json
        ^~~~~~~~~~~~~
json.hpp:488:8: error: all member functions in class ‘nlohmann::detail::has_non_default_from_json<BasicJsonType, T>’ are private [-Werror=ctor-dtor-privacy]
 struct has_non_default_from_json
        ^~~~~~~~~~~~~~~~~~~~~~~~~
json.hpp:505:8: error: all member functions in class ‘nlohmann::detail::has_to_json<BasicJsonType, T>’ are private [-Werror=ctor-dtor-privacy]
 struct has_to_json
        ^~~~~~~~~~~
In file included from main.cpp:1:0:
json.hpp: In instantiation of ‘void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType&, bool, bool, unsigned int, unsigned int) [with BasicJsonType = nlohmann::basic_json<>]’:
json.hpp:13069:13:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::dump(int, char, bool) const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::string_t = std::__cxx11::basic_string<char>]’
json.hpp:18827:25:   required from here
json.hpp:9809:9: error: switch missing default case [-Werror=switch-default]
         switch (val.m_type)
         ^~~~~~
cc1plus: all warnings being treated as errors

GNU/Linux/Fedora, gcc

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180712 (Red Hat 7.3.1-6) (GCC) 
@Wittmaxi
Copy link
Author

Wittmaxi commented Sep 4, 2018

Putting a #pragma GCC system_header at top of json.hpp did the trick. You should consider releasing the file with that pragma and/or fixing those warnings.

Keep up the great work :-)!

@gregmarr
Copy link
Contributor

gregmarr commented Sep 4, 2018

There are multiple options as far as switch handling of enums, and it is impossible to make code clean to all of them at once, as one warns when there is no default case, and one warns when the default case is used when all the elements of an enum are also specified. See #889 and #555

You should be able to do the same as #pragma GCC system_header by including it with <json.hpp> instead of "json.hpp".

@Wittmaxi
Copy link
Author

Wittmaxi commented Sep 4, 2018

Okay that makes perfect sense! I can't include it with <json.hpp> because I need the file to be in the project folder

@theodelrieu
Copy link
Contributor

I would put it in a third_party folder, then adding -isystem third_party to compiler options

@Wittmaxi
Copy link
Author

Wittmaxi commented Sep 4, 2018

Mhh. that might work as well.

nlohmann added a commit that referenced this issue Sep 6, 2018
@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Sep 6, 2018
@nlohmann
Copy link
Owner

nlohmann commented Sep 6, 2018

I fixed the "all member functions are private" warning. As @gregmarr wrote, there is nothing consistent we can do about warnings in switches.

@nlohmann nlohmann added this to the Release 3.2.1 milestone Sep 6, 2018
@nlohmann nlohmann self-assigned this Sep 6, 2018
@Wittmaxi
Copy link
Author

Wittmaxi commented Sep 6, 2018

Thank you! I will close the issue now, I think all that CAN be done was done.

@Wittmaxi Wittmaxi closed this as completed Sep 6, 2018
FaultyPine added a commit to FaultyPine/dolphin that referenced this issue Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

4 participants