From c0d33975d11f19a9786667927cf84eb380966283 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Mon, 12 Aug 2019 17:00:35 -0500 Subject: [PATCH] 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 5ffe0ab6dff..344cc63a694 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 9962da7dbe3..b1d7f163f07 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 65d535c453c..8e4ac8fc515 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 857983d9053..02e18adc580 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__ */