This is an automated email from the ASF dual-hosted git repository.
jdanek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
The following commit(s) were added to refs/heads/main by this push:
new d2dbfd47a PROTON-2773: add `PN_FALLTHROUGH` macro ready for c++17/c21
(#408)
d2dbfd47a is described below
commit d2dbfd47ab8a6b9be9fde222801ffef7e7d2bc00
Author: Jiri Daněk <[email protected]>
AuthorDate: Fri Oct 20 15:32:28 2023 +0200
PROTON-2773: add `PN_FALLTHROUGH` macro ready for c++17/c21 (#408)
---
CMakeLists.txt | 6 +++---
c/experimental/raw_plus_tls2.c | 3 ++-
c/include/proton/annotations.h | 19 +++++++++++++++++++
c/src/core/decoder.c | 2 ++
c/src/core/encoder.c | 2 +-
c/src/core/message.c | 2 ++
c/src/core/transport.c | 3 ++-
c/src/messenger/transform.c | 2 +-
c/src/sasl/sasl.c | 3 ++-
9 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7b81e529e..3514f6aae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -163,9 +163,9 @@ set (COMMON_WARNING_GNU "-Wall -pedantic-errors")
set (COMMON_WARNING_Clang "-Wall -pedantic")
set (COMMON_WARNING_MSVC "")
-set (CC_WARNING_GNU "-Wno-unused-parameter -Wstrict-prototypes -Wvla
-Wsign-compare -Wwrite-strings")
-set (CC_WARNING_Clang "-Wno-unused-parameter -Wstrict-prototypes -Wvla
-Wsign-compare -Wwrite-strings")
-set (CC_WARNING_MSVC "/wd4244 /wd4267 /wd4800 /wd4996")
+set (CC_WARNING_GNU "-Wno-unused-parameter -Wstrict-prototypes -Wvla
-Wsign-compare -Wwrite-strings -Wimplicit-fallthrough=3")
+set (CC_WARNING_Clang "-Wno-unused-parameter -Wstrict-prototypes -Wvla
-Wsign-compare -Wwrite-strings -Wimplicit-fallthrough")
+set (CC_WARNING_MSVC "/wd4244 /wd4267 /wd4800 /wd4996 /we26819")
set (CXX_WARNING_GNU "")
set (CXX_WARNING_Clang "")
diff --git a/c/experimental/raw_plus_tls2.c b/c/experimental/raw_plus_tls2.c
index f65c290d1..0dc449610 100644
--- a/c/experimental/raw_plus_tls2.c
+++ b/c/experimental/raw_plus_tls2.c
@@ -19,6 +19,7 @@
#include "thread.h"
+#include <proton/annotations.h>
#include <proton/raw_connection.h>
#include <proton/tls.h>
#include <proton/listener.h>
@@ -586,7 +587,7 @@ static bool handle(jabber_t* j, pn_event_t* event) {
case PN_PROACTOR_INACTIVE:
printf("**proactor inactive: connections and listeners finalized\n");
- // fall through
+ PN_FALLTHROUGH;
case PN_PROACTOR_INTERRUPT: {
pn_proactor_t *proactor = pn_event_proactor(event);
pn_proactor_interrupt(proactor);
diff --git a/c/include/proton/annotations.h b/c/include/proton/annotations.h
index 82e3df310..56ae7a904 100644
--- a/c/include/proton/annotations.h
+++ b/c/include/proton/annotations.h
@@ -90,4 +90,23 @@
#endif
#endif
+// fallthrough
+#if defined __cplusplus && defined __has_cpp_attribute
+ #if __has_cpp_attribute(fallthrough) && __cplusplus >=
__has_cpp_attribute(fallthrough)
+ #define PN_FALLTHROUGH [[fallthrough]]
+ #endif
+#elif defined __STDC_VERSION__ && defined __has_c_attribute
+ #if __has_c_attribute(fallthrough) && __STDC_VERSION__ >=
__has_c_attribute(fallthrough)
+ #define PN_FALLTHROUGH [[fallthrough]]
+ #endif
+#endif
+#if !defined PN_FALLTHROUGH && defined __has_attribute
+ #if __has_attribute(__fallthrough__)
+ #define PN_FALLTHROUGH __attribute__((__fallthrough__))
+ #endif
+#endif
+#if !defined PN_FALLTHROUGH
+ #define PN_FALLTHROUGH (void)0
+#endif
+
#endif /* annotations.h */
diff --git a/c/src/core/decoder.c b/c/src/core/decoder.c
index b487c96a7..fbda81495 100644
--- a/c/src/core/decoder.c
+++ b/c/src/core/decoder.c
@@ -354,6 +354,7 @@ static int pni_decoder_decode_value(pn_decoder_t *decoder,
pn_data_t *data, uint
{
case PNE_ARRAY8:
min_expected_size += 1; // Array has a constructor of at least 1 byte
+ PN_FALLTHROUGH;
case PNE_LIST8:
case PNE_MAP8:
min_expected_size += 1; // All these types have a count
@@ -366,6 +367,7 @@ static int pni_decoder_decode_value(pn_decoder_t *decoder,
pn_data_t *data, uint
break;
case PNE_ARRAY32:
min_expected_size += 1; // Array has a constructor of at least 1 byte
+ PN_FALLTHROUGH;
case PNE_LIST32:
case PNE_MAP32:
min_expected_size += 4; // All these types have a count
diff --git a/c/src/core/encoder.c b/c/src/core/encoder.c
index 8fb7acfc1..cd0b5fb35 100644
--- a/c/src/core/encoder.c
+++ b/c/src/core/encoder.c
@@ -362,7 +362,7 @@ static int pni_encoder_exit(void *ctx, pn_data_t *data,
pni_node_t *node)
if ((node->described && node->children == 1) || (!node->described &&
node->children == 0)) {
pn_encoder_writef8(encoder, pn_type2code(encoder, node->type));
}
- // Fallthrough
+ PN_FALLTHROUGH;
case PN_LIST:
case PN_MAP:
pos = encoder->position;
diff --git a/c/src/core/message.c b/c/src/core/message.c
index b4def0b14..304d91b41 100644
--- a/c/src/core/message.c
+++ b/c/src/core/message.c
@@ -80,9 +80,11 @@ void pni_msgid_clear(pn_atom_t* msgid) {
case PN_BINARY:
case PN_STRING:
free((void*)msgid->u.as_bytes.start);
+ PN_FALLTHROUGH;
case PN_ULONG:
case PN_UUID:
msgid->type = PN_NULL;
+ PN_FALLTHROUGH;
case PN_NULL:
return;
default:
diff --git a/c/src/core/transport.c b/c/src/core/transport.c
index 5dd37e43e..260e894c9 100644
--- a/c/src/core/transport.c
+++ b/c/src/core/transport.c
@@ -38,6 +38,7 @@
#include "logger_private.h"
#include "proton/event.h"
+#include "proton/annotations.h"
#include <stddef.h>
#include <string.h>
@@ -2586,7 +2587,7 @@ static ssize_t pn_input_read_amqp_header(pn_transport_t*
transport, unsigned int
return 8;
case PNI_PROTOCOL_INSUFFICIENT:
if (!eos) return 0;
- /* Fallthru */
+ PN_FALLTHROUGH;
default:
break;
}
diff --git a/c/src/messenger/transform.c b/c/src/messenger/transform.c
index bd58e2172..f386aadaa 100644
--- a/c/src/messenger/transform.c
+++ b/c/src/messenger/transform.c
@@ -130,7 +130,7 @@ static bool pni_match_r(pn_matcher_t *matcher, const char
*pattern, const char *
if (match) pni_sub(matcher, group, text, matched);
return match;
}
- // Fallthrough
+ PN_FALLTHROUGH;
default:
match = pni_match_r(matcher, pattern, text + 1, group, matched + 1);
if (!match) {
diff --git a/c/src/sasl/sasl.c b/c/src/sasl/sasl.c
index 517a73dc4..b58045737 100644
--- a/c/src/sasl/sasl.c
+++ b/c/src/sasl/sasl.c
@@ -32,6 +32,7 @@
#include "platform/platform_fmt.h"
#include "protocol.h"
+#include "proton/annotations.h"
#include "proton/ssl.h"
#include "proton/types.h"
@@ -600,7 +601,7 @@ static ssize_t pn_input_read_sasl_header(pn_transport_t*
transport, unsigned int
return SASL_HEADER_LEN;
case PNI_PROTOCOL_INSUFFICIENT:
if (!eos) return 0;
- /* Fallthru */
+ PN_FALLTHROUGH;
default:
break;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]