Skip to content

Conversation

thughes
Copy link
Contributor

@thughes thughes commented Oct 3, 2025

When using clang to build for RISC-V with these configs:

CONFIG_CPP=y
CONFIG_USERSPACE=n
CONFIG_SMP=n
CONFIG_FPU_SHARING=n

we get the following warnings:

include/zephyr/arch/riscv/structs.h:11:1: error: empty struct has size 0
in C, size 1 in C++ [-Werror,-Wextern-c-compat]
11 | struct _cpu_arch {
| ^

include/zephyr/arch/riscv/thread.h:68:1: error: empty struct has size 0
in C, size 1 in C++ [-Werror,-Wextern-c-compat]
68 | struct _thread_arch {
| ^

This commit adds a test with those configs to verify compilation
succeeds. Although gcc doesn't emit these warnings, we can test with gcc
as well with a BUILD_ASSERT in include/zephyr/arch/riscv/thread.h and
include/zephyr/arch/riscv/structs.h that was added in #96943.

When using clang to build for RISC-V with these configs:

CONFIG_CPP=y
CONFIG_USERSPACE=n
CONFIG_SMP=n
CONFIG_FPU_SHARING=n

we get the following warnings:

include/zephyr/arch/riscv/structs.h:11:1: error: empty struct has size 0
in C, size 1 in C++ [-Werror,-Wextern-c-compat]
11 | struct _cpu_arch {
| ^

include/zephyr/arch/riscv/thread.h:68:1: error: empty struct has size 0
in C, size 1 in C++ [-Werror,-Wextern-c-compat]
68 | struct _thread_arch {
| ^

This commit adds a test with those configs to verify compilation
succeeds. Although gcc doesn't emit these warnings, we can test with gcc
as well with a BUILD_ASSERT in include/zephyr/arch/riscv/thread.h and
include/zephyr/arch/riscv/structs.h.

Signed-off-by: Tom Hughes <[email protected]>
@thughes thughes force-pushed the push-tukkmmylosnk branch from 38e5a41 to dcd2b17 Compare October 3, 2025 00:04
@thughes thughes changed the title tests: riscv: Add test to verify C++ compilation tests: lib: cpp: cxx: Add test to verify C++ compilation Oct 3, 2025
Copy link

sonarqubecloud bot commented Oct 3, 2025

@thughes thughes marked this pull request as ready for review October 3, 2025 21:08
@zephyrbot zephyrbot added area: Tests Issues related to a particular existing or missing test area: C++ labels Oct 3, 2025
- CONFIG_STD_CPP23=y
# Verify struct _cpu_arch struct _thread_arch are compatible with C++ when
# specific configs are enabled.
cpp.main.empty_struct_size:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to limit this to run on native_sim and also to elicit coverage with both gcc and llvm.

    platform_allow:
      - native_sim
    integration_platforms:
      - native_sim
    integration_toolchains:
      - host
      - llvm

Comment on lines +81 to +88
# Verify struct _cpu_arch struct _thread_arch are compatible with C++ when
# specific configs are enabled.
cpp.main.empty_struct_size:
build_only: true
extra_configs:
- CONFIG_USERSPACE=n
- CONFIG_SMP=n
- CONFIG_FPU_SHARING=n
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICS, this is a RISC-V specific issue; so, this should be limited to arch_allow: riscv. Also, a RISC-V integration_platforms should be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C++ area: Tests Issues related to a particular existing or missing test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants