Json: -Wmismatched-tags in 3.5.0?

Created on 23 Dec 2018  路  8Comments  路  Source: nlohmann/json

While I'm aware of the workarounds, I thought you might find the following interesting.

  • What is the issue you have?

-Wmismatched-tags using Clang v6.0 on Ubuntu 18.04:

json.hpp:1799:1: error: 'tuple_size' defined as a class template here but previously declared as a struct template [-Werror,-Wmismatched-tags]
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
^
/usr/include/c++/7.3.0/utility:84:5: note: did you mean class here?
    struct tuple_size;
    ^
[...]
json.hpp:1803:1: error: 'tuple_element' defined as a class template here but previously declared as a struct template [-Werror,-Wmismatched-tags]
class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
^
/usr/include/c++/7.3.0/utility:129:5: note: did you mean class here?
    struct tuple_element;
    ^
2 errors generated.
  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

Attempted to update Warzone 2100 from nlohmann/json 3.4.0 to 3.5.0.
(Compilation succeeds with 3.4.0. CI treats many warnings as errors. -std=gnu++11)

  • What is the expected behavior?

Compilation succeeds without error / warnings.

  • And what is the actual behavior instead?

[-Wmismatched-tags] is triggered

The CXX compiler identification is Clang 6.0.0
on Ubuntu 18.04

  • Did you use a released version of the library or the version from the develop branch?

3.5.0 release

release item improvement proposed fix

Most helpful comment

Note that the C++ standard declares tuple_size and tuple_element as classes, but defines them as structs, see paragraph 19.4.4 of the current draft.

I'm also for explicitly disabling those warnings.

All 8 comments

I'm encountering the same warning, note that some standard libraries are defining std::tuple_size and std::tuple_element wrongly as class whereas struct would be right.

In a library of mine, I came up with the following workarround to suppress the warnings on my own std::tuple_size and std::tuple_element specialization, since one can't do much if some standard library versions define it differently:

namespace std {
// The GCC standard library defines tuple_size as class and struct
// which triggers a warning here.
#if defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmismatched-tags"
#endif
template <typename... Args>
struct tuple_size<cti::result<Args...>>
    : std::integral_constant<size_t, sizeof...(Args)> {};

template <std::size_t I, typename... Args>
struct tuple_element<I, cti::result<Args...>>
    : tuple_element<I, tuple<Args...>> {};
#if defined(__clang__)
#pragma GCC diagnostic pop
#endif
} // namespace std

An additional reference on this issue:

Thanks for reporting. I had a warning before I released and adjusted the code wrt. to the examples from cppreference.com. Now, I do not get any warning with GCC 9 and Clang 8.

It looks like this might be fixed in Clang 8, but Clang 7 may also trigger it. (Was playing around with a small example linked in the isocpp group post above.)

@nlohmann: Would disabling the -Wmismatched-tags warning for Clang around the tuple_size and tuple_element specializations (similar to what @Naios suggested) be an acceptable PR?

@past-due Yes, of course are PRs welcome!

Note that the C++ standard declares tuple_size and tuple_element as classes, but defines them as structs, see paragraph 19.4.4 of the current draft.

I'm also for explicitly disabling those warnings.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Please don't close, stale bot.

Was this page helpful?
0 / 5 - 0 ratings