nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
41.33k stars 6.58k forks source link

GCC compiler warning about violating the C++ One Definition Rule [-Wodr] #4116

Closed mgerhardy closed 10 months ago

mgerhardy commented 10 months ago

Description

/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***8475:***: warning: type ‘union json_value’ violates the C++ One Definition Rule [-Wodr]
***8475 |     union json_value
      |           ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***8475:***: note: a different type is defined in another translation unit
***8475 |     union json_value
      |           ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***8478:***9: note: the first difference of corresponding definitions is field ‘object’
***8478 |         object_t* object;
      |                   ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***8478:***9: note: a field of same name but different type is defined in another translation unit
***8478 |         object_t* object;
      |                   ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***8475:***: note: type name ‘std::map<std::__cxx***::basic_string<char, std::char_traits<char>, std::allocator<char> >, nlohmann::basic_json<std::map, std::vector, std::__cxx***::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >, std::less<void>, std::allocator<std::pair<std::__cxx***::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx***::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > > > >’ should match type name ‘std::map<std::__cxx***::basic_string<char, std::char_traits<char>, std::allocator<char> >, nlohmann::basic_json<std::map, std::vector, std::__cxx***::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >, std::less<std::__cxx***::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx***::basic_string<char, std::char_traits<char>, std::allocator<char> > const, nlohmann::basic_json<std::map, std::vector, std::__cxx***::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > > > >’
***8475 |     union json_value
      |           ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***7677:7: warning: type ‘struct basic_json’ violates the C++ One Definition Rule [-Wodr]
***7677 | class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
      |       ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***7677:7: note: a different type is defined in another translation unit
***7677 | class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
      |       ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:247***4:***6: note: the first difference of corresponding definitions is field ‘m_value’
247***4 |     json_value m_value = {};
      |                ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:247***4:***6: note: a field of same name but different type is defined in another translation unit
247***4 |     json_value m_value = {};
      |                ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***8475:***: note: type ‘union json_value’ itself violates the C++ One Definition Rule
***8475 |     union json_value
      |           ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***7677:7: note: type ‘struct basic_json’ itself violates the C++ One Definition Rule
***7677 | class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
      |       ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:6240:7: warning: type ‘struct json_sax_dom_callback_parser’ violates the C++ One Definition Rule [-Wodr]
 6240 | class json_sax_dom_callback_parser
      |       ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:6240:7: note: a different type is defined in another translation unit
 6240 | class json_sax_dom_callback_parser
      |       ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:6543:***9: note: the first difference of corresponding definitions is field ‘discarded’
 6543 |     BasicJsonType discarded = BasicJsonType::value_t::discarded;
      |                   ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:6543:***9: note: a field of same name but different type is defined in another translation unit
 6543 |     BasicJsonType discarded = BasicJsonType::value_t::discarded;
      |                   ^
/home/runner/work/vengi/vengi/contrib/libs/json/json.hpp:***7677:7: note: type ‘struct basic_json’ itself violates the C++ One Definition Rule
***7677 | class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
      |       ^

Reproduction steps

Compile with gcc and -Wodr

Expected vs. actual results

no warnings

Minimal code example

No response

Error messages

No response

Compiler and operating system

gcc/linux

Library version

v3.10.4

Validation

mgerhardy commented 10 months ago

sorry, the warning comes with tinygltf - i will open a ticket there to update the lib first.