From 09a281d7a01415160c261980d622487c93b7cb4f Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 17:00:35 -0500 Subject: [PATCH 1/4] subsys/testsuite: rearrange for standard use of extern "C" Consistently place C++ use of extern "C" after all include directives, within the negative branch of _ASMLANGUAGE if used. Background from issue #17997: Declarations that use C linkage should be placed within extern "C" so the language linkage is correct when the header is included by a C++ compiler. Similarly #include directives should be outside the extern "C" to ensure the language-specific default linkage is applied to any declarations provided by the included header. See: https://en.cppreference.com/w/cpp/language/language_linkage Signed-off-by: Peter Bigot --- subsys/testsuite/ztest/include/ztest.h | 15 ++++++++++----- subsys/testsuite/ztest/include/ztest_assert.h | 8 ++++++++ subsys/testsuite/ztest/include/ztest_mock.h | 8 ++++++++ subsys/testsuite/ztest/include/ztest_test.h | 8 ++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/subsys/testsuite/ztest/include/ztest.h b/subsys/testsuite/ztest/include/ztest.h index 5ffe0ab6dff5e..344cc63a6949e 100644 --- a/subsys/testsuite/ztest/include/ztest.h +++ b/subsys/testsuite/ztest/include/ztest.h @@ -20,10 +20,6 @@ #ifndef __ZTEST_H__ #define __ZTEST_H__ -#ifdef __cplusplus -extern "C" { -#endif - /** * @defgroup ztest Zephyr testing suite */ @@ -44,21 +40,30 @@ extern "C" { /* FIXME: Properly integrate with Zephyr's arch specific code */ #define CONFIG_X86 1 #define CONFIG_PRINTK 1 +#ifdef __cplusplus +extern "C" { +#endif struct esf; typedef struct esf z_arch_esf_t; +#ifdef __cplusplus +} #endif +#endif /* KERNEL */ #include #define PRINT printk #include - #include #include #include #include +#ifdef __cplusplus +extern "C" { +#endif + void test_main(void); #ifdef __cplusplus diff --git a/subsys/testsuite/ztest/include/ztest_assert.h b/subsys/testsuite/ztest/include/ztest_assert.h index 9962da7dbe304..b1d7f163f0754 100644 --- a/subsys/testsuite/ztest/include/ztest_assert.h +++ b/subsys/testsuite/ztest/include/ztest_assert.h @@ -19,6 +19,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + void ztest_test_fail(void); #if CONFIG_ZTEST_ASSERT_VERBOSE == 0 @@ -214,4 +218,8 @@ static inline void z_zassert(int cond, * @} */ +#ifdef __cplusplus +} +#endif + #endif /* __ZTEST_ASSERT_H__ */ diff --git a/subsys/testsuite/ztest/include/ztest_mock.h b/subsys/testsuite/ztest/include/ztest_mock.h index 65d535c453c12..8e4ac8fc5152c 100644 --- a/subsys/testsuite/ztest/include/ztest_mock.h +++ b/subsys/testsuite/ztest/include/ztest_mock.h @@ -91,6 +91,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + void z_init_mock(void); int z_cleanup_mock(void); @@ -101,6 +105,10 @@ void z_ztest_check_expected_value(const char *fn, const char *param, void z_ztest_returns_value(const char *fn, uintptr_t value); uintptr_t z_ztest_get_return_value(const char *fn); +#ifdef __cplusplus +} +#endif + #else /* !CONFIG_ZTEST_MOCKING */ #define z_init_mock() diff --git a/subsys/testsuite/ztest/include/ztest_test.h b/subsys/testsuite/ztest/include/ztest_test.h index 857983d9053ff..02e18adc5804c 100644 --- a/subsys/testsuite/ztest/include/ztest_test.h +++ b/subsys/testsuite/ztest/include/ztest_test.h @@ -15,6 +15,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + struct unit_test { const char *name; void (*test)(void); @@ -171,4 +175,8 @@ extern struct k_mem_domain ztest_mem_domain; * @} */ +#ifdef __cplusplus +} +#endif + #endif /* __ZTEST_ASSERT_H__ */ From 9d83a9ee5cec2f67cbf51ec33923a745f5a8b27d Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:55:24 -0500 Subject: [PATCH 2/4] samples/subsys/logging/logger: rearrange for standard use of extern "C" Consistently place C++ use of extern "C" after all include directives, within the negative branch of _ASMLANGUAGE if used. Background from issue #17997: Declarations that use C linkage should be placed within extern "C" so the language linkage is correct when the header is included by a C++ compiler. Similarly #include directives should be outside the extern "C" to ensure the language-specific default linkage is applied to any declarations provided by the included header. See: https://en.cppreference.com/w/cpp/language/language_linkage Signed-off-by: Peter Bigot --- samples/subsys/logging/logger/src/sample_module.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/subsys/logging/logger/src/sample_module.h b/samples/subsys/logging/logger/src/sample_module.h index 0a80a214a6b5d..6293793c94436 100644 --- a/samples/subsys/logging/logger/src/sample_module.h +++ b/samples/subsys/logging/logger/src/sample_module.h @@ -6,10 +6,11 @@ #ifndef SAMPLE_MODULE_H #define SAMPLE_MODULE_H +#include + #ifdef __cplusplus extern "C" { #endif -#include #define MODULE_NAME sample_module From f6d75ae45b35e1fd5f7197ec830f877e74153fc0 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 12:56:04 -0500 Subject: [PATCH 3/4] subsys/debug/tracing: rearrange for standard use of extern "C" Consistently place C++ use of extern "C" after all include directives, within the negative branch of _ASMLANGUAGE if used. Background from issue #17997: Declarations that use C linkage should be placed within extern "C" so the language linkage is correct when the header is included by a C++ compiler. Similarly #include directives should be outside the extern "C" to ensure the language-specific default linkage is applied to any declarations provided by the included header. See: https://en.cppreference.com/w/cpp/language/language_linkage Signed-off-by: Peter Bigot --- subsys/debug/tracing/include/tracing_ctf.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/subsys/debug/tracing/include/tracing_ctf.h b/subsys/debug/tracing/include/tracing_ctf.h index 041a4f316837e..3a300354a917e 100644 --- a/subsys/debug/tracing/include/tracing_ctf.h +++ b/subsys/debug/tracing/include/tracing_ctf.h @@ -7,14 +7,14 @@ #ifndef _TRACE_CTF_H #define _TRACE_CTF_H -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include +#ifdef __cplusplus +extern "C" { +#endif + void sys_trace_thread_switched_out(void); void sys_trace_thread_switched_in(void); void sys_trace_thread_priority_set(struct k_thread *thread); From 220f480f16390a1e89e55164987338fe42e6fbc0 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 16:45:10 -0500 Subject: [PATCH 4/4] lib/libc: rearrange for standard use of extern "C" Consistently place C++ use of extern "C" after all include directives, within the negative branch of _ASMLANGUAGE if used. Background from issue #17997: Declarations that use C linkage should be placed within extern "C" so the language linkage is correct when the header is included by a C++ compiler. Similarly #include directives should be outside the extern "C" to ensure the language-specific default linkage is applied to any declarations provided by the included header. See: https://en.cppreference.com/w/cpp/language/language_linkage Signed-off-by: Peter Bigot --- lib/libc/minimal/include/time.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/libc/minimal/include/time.h b/lib/libc/minimal/include/time.h index d23e9296eaf59..2de85621d1632 100644 --- a/lib/libc/minimal/include/time.h +++ b/lib/libc/minimal/include/time.h @@ -11,6 +11,7 @@ #include #include #include +#include /* Minimal time.h to fulfill the requirements of certain libraries * like mbedTLS and to support time APIs. @@ -42,8 +43,6 @@ typedef _TIME_T_ time_t; typedef _SUSECONDS_T_ suseconds_t; #endif -#include - /* * Conversion between civil time and UNIX time. The companion * localtime() and inverse mktime() are not provided here since they