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

-Wmismatched-tags in 3.5.0? #1401

Closed
past-due opened this issue Dec 22, 2018 · 8 comments
Closed

-Wmismatched-tags in 3.5.0? #1401

past-due opened this issue Dec 22, 2018 · 8 comments
Assignees
Labels
release item: ⚡ improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@past-due
Copy link
Contributor

past-due commented Dec 22, 2018

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

@Naios
Copy link

Naios commented Dec 23, 2018

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

@past-due
Copy link
Contributor Author

An additional reference on this issue:

@nlohmann
Copy link
Owner

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.

@past-due
Copy link
Contributor Author

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?

@nlohmann
Copy link
Owner

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

@theodelrieu
Copy link
Contributor

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.

Minoru added a commit to newsboat/newsboat that referenced this issue Dec 29, 2018
This reverts commit b7cd350.

json 3.5.0 triggers -Wmismatched-tags, and since we treat all warnings
as errors, this fails the build. Upstream is aware of the problem:
nlohmann/json#1401

It doesn't look like 3.5.0 contains any critical bugfixes, so I am
simply rolling back to the previous version.
@stale
Copy link

stale bot commented Jan 30, 2019

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.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jan 30, 2019
@past-due
Copy link
Contributor Author

Please don't close, stale bot.

@stale stale bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jan 30, 2019
@nlohmann nlohmann self-assigned this Feb 10, 2019
@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed state: waiting for PR labels Feb 10, 2019
@nlohmann nlohmann added this to the Release 3.5.1 milestone Feb 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release item: ⚡ improvement 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