Skip to content
Snippets Groups Projects
Commit 3ce62ef8 authored by Roman Tsisyk's avatar Roman Tsisyk
Browse files

Add FALLTHROUGH macro

The fallthrough attribute with a null statement serves as a fallthrough
statement. It hints to the compiler that a statement that falls through
to another case label, or user-defined label in a switch statement is
intentional and thus the -Wimplicit-fallthrough warning must not trigger.
The fallthrough attribute may appear at most once in each attribute list,
and may not be mixed with other attributes. It can only be used in a switch
statement (the compiler will issue an error otherwise), after a preceding
statement and before a logically succeeding case label, or user-defined
label.

https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
parent 6e7c1059
No related branches found
No related tags found
No related merge requests found
......@@ -8,12 +8,6 @@ macro(libmisc_build)
${PROJECT_SOURCE_DIR}/third_party/qsort_arg.c
)
if (CC_HAS_WNO_IMPLICIT_FALLTHROUGH)
# Disable false-positive warnings in switch() {} block
set_source_files_properties(${PROJECT_SOURCE_DIR}/third_party/base64.c
PROPERTIES COMPILE_FLAGS -Wno-implicit-fallthrough)
endif()
if (NOT HAVE_MEMMEM)
list(APPEND misc_src
${PROJECT_SOURCE_DIR}/third_party/memmem.c
......
......@@ -364,6 +364,29 @@ strindex(const char **haystack, const char *needle, uint32_t hmax);
/** Function Attributes }}} */
/** {{{ Statement Attributes */
/**
* The fallthrough attribute with a null statement serves as a fallthrough
* statement. It hints to the compiler that a statement that falls through
* to another case label, or user-defined label in a switch statement is
* intentional and thus the -Wimplicit-fallthrough warning must not trigger.
* The fallthrough attribute may appear at most once in each attribute list,
* and may not be mixed with other attributes. It can only be used in a switch
* statement (the compiler will issue an error otherwise), after a preceding
* statement and before a logically succeeding case label, or user-defined
* label.
*/
#if defined(__cplusplus) && __has_cpp_attribute(fallthrough)
# define FALLTHROUGH [[fallthrough]]
#elif __has_attribute(fallthrough) || (defined(__GNUC__) && __GNUC__ >= 7)
# define FALLTHROUGH __attribute__((fallthrough))
#else
# define FALLTHROUGH
#endif
/** Statement Attributes }}} */
/** \endcond public */
void close_all_xcpt(int fdc, ...);
......
......@@ -27,6 +27,8 @@
* SUCH DAMAGE.
*/
#include "third_party/base64.h"
#include <trivia/util.h>
/*
* This is part of the libb64 project, and has been placed in the
* public domain. For details, see
......@@ -92,6 +94,7 @@ base64_encode_block(const char *in_bin, int in_len,
result = (fragment & 0x0fc) >> 2;
*out_pos++ = base64_encode_value(result);
result = (fragment & 0x003) << 4;
FALLTHROUGH;
case step_B:
if (in_pos == in_end || out_pos >= out_end) {
state->result = result;
......@@ -102,6 +105,7 @@ base64_encode_block(const char *in_bin, int in_len,
result |= (fragment & 0x0f0) >> 4;
*out_pos++ = base64_encode_value(result);
result = (fragment & 0x00f) << 2;
FALLTHROUGH;
case step_C:
if (in_pos == in_end || out_pos + 2 >= out_end) {
state->result = result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment