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

Fix fallthrough warning for JSON archive code. #575

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/cereal/archives/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,13 @@ namespace cereal
{
case NodeType::StartArray:
itsWriter.StartArray();
CEREAL_FALL_THROUGH;
case NodeType::InArray:
itsWriter.EndArray();
break;
case NodeType::StartObject:
itsWriter.StartObject();
CEREAL_FALL_THROUGH;
case NodeType::InObject:
itsWriter.EndObject();
break;
Expand Down
24 changes: 24 additions & 0 deletions include/cereal/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,28 @@
#endif // end !defined(CEREAL_HAS_NOEXCEPT)
#endif // ifndef CEREAL_NOEXCEPT


// ######################################################################
//! Defines the CEREAL_FALL_THROUGH macro to suppress fall-through warnings
//! if the compiler supports it.

// Use the C++17 atribute if available
#if defined __has_cpp_attribute
#if __has_cpp_attribute(fallthrough)
#define CEREAL_FALL_THROUGH [[fallthrough]]
#endif // end __has_cpp_attribute(fallthrough)
#endif // end defined __has_cpp_attribute

// Otherwise try the non-portable GNU extension
#ifndef CEREAL_FALL_THROUGH
#if defined(__GNUC__) && __GNUC__ >= 7
#define CEREAL_FALL_THROUGH __attribute__ ((fallthrough))
#endif // end __GNUC__ >= 7
#endif // end !defined CEREAL_FALL_THROUGH

// Otherwise make it a no-op
#ifndef CEREAL_FALL_THROUGH
#define CEREAL_FALL_THROUGH ((void)0)
#endif // end !defined CEREAL_FALL_THROUGH

#endif // CEREAL_MACROS_HPP_