Skip to content

Commit c0d3397

Browse files
pabigotioannisg
authored andcommitted
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 zephyrproject-rtos#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 <[email protected]>
1 parent f31e492 commit c0d3397

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

subsys/testsuite/ztest/include/ztest.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
#ifndef __ZTEST_H__
2121
#define __ZTEST_H__
2222

23-
#ifdef __cplusplus
24-
extern "C" {
25-
#endif
26-
2723
/**
2824
* @defgroup ztest Zephyr testing suite
2925
*/
@@ -44,21 +40,30 @@ extern "C" {
4440
/* FIXME: Properly integrate with Zephyr's arch specific code */
4541
#define CONFIG_X86 1
4642
#define CONFIG_PRINTK 1
43+
#ifdef __cplusplus
44+
extern "C" {
45+
#endif
4746
struct esf;
4847
typedef struct esf z_arch_esf_t;
48+
#ifdef __cplusplus
49+
}
4950
#endif
51+
#endif /* KERNEL */
5052

5153
#include <sys/printk.h>
5254
#define PRINT printk
5355

5456
#include <zephyr.h>
5557

56-
5758
#include <ztest_assert.h>
5859
#include <ztest_mock.h>
5960
#include <ztest_test.h>
6061
#include <tc_util.h>
6162

63+
#ifdef __cplusplus
64+
extern "C" {
65+
#endif
66+
6267
void test_main(void);
6368

6469
#ifdef __cplusplus

subsys/testsuite/ztest/include/ztest_assert.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <stdio.h>
2020
#include <string.h>
2121

22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
2226
void ztest_test_fail(void);
2327
#if CONFIG_ZTEST_ASSERT_VERBOSE == 0
2428

@@ -214,4 +218,8 @@ static inline void z_zassert(int cond,
214218
* @}
215219
*/
216220

221+
#ifdef __cplusplus
222+
}
223+
#endif
224+
217225
#endif /* __ZTEST_ASSERT_H__ */

subsys/testsuite/ztest/include/ztest_mock.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@
9191

9292
#include <zephyr/types.h>
9393

94+
#ifdef __cplusplus
95+
extern "C" {
96+
#endif
97+
9498
void z_init_mock(void);
9599
int z_cleanup_mock(void);
96100

@@ -101,6 +105,10 @@ void z_ztest_check_expected_value(const char *fn, const char *param,
101105
void z_ztest_returns_value(const char *fn, uintptr_t value);
102106
uintptr_t z_ztest_get_return_value(const char *fn);
103107

108+
#ifdef __cplusplus
109+
}
110+
#endif
111+
104112
#else /* !CONFIG_ZTEST_MOCKING */
105113

106114
#define z_init_mock()

subsys/testsuite/ztest/include/ztest_test.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
#include <app_memory/app_memdomain.h>
1717

18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
1822
struct unit_test {
1923
const char *name;
2024
void (*test)(void);
@@ -171,4 +175,8 @@ extern struct k_mem_domain ztest_mem_domain;
171175
* @}
172176
*/
173177

178+
#ifdef __cplusplus
179+
}
180+
#endif
181+
174182
#endif /* __ZTEST_ASSERT_H__ */

0 commit comments

Comments
 (0)