diff --git a/.github/workflows/cmake_win.yml b/.github/workflows/cmake_win.yml index 3244235d2..4058e46d5 100644 --- a/.github/workflows/cmake_win.yml +++ b/.github/workflows/cmake_win.yml @@ -1,4 +1,4 @@ -name: CMake and Windows +name: Windows on: push: diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index bfd94c300..9c853aaa3 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -18,8 +18,10 @@ jobs: sanitizer: [thread, address, undefined] env: CC: clang-18 + CXX: clang++-18 CMAKE_GENERATOR: Ninja CFLAGS: "-fsanitize=${{ matrix.sanitizer }} -fno-sanitize-recover=all -fno-sanitize=function" + CXXFLAGS: "-fsanitize=${{ matrix.sanitizer }} -fno-sanitize-recover=all -fno-sanitize=function" ASAN_OPTIONS: fast_unwind_on_malloc=0 steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index e55f145d5..6aab060b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,15 +83,15 @@ endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang") add_compile_options( - -Wshorten-64-to-32 -Wno-gnu-zero-variadic-macro-arguments -Wno-c2x-extensions ) + add_compile_options("$<$:-Wshorten-64-to-32>") endif() check_c_compiler_flag("-Watomic-implicit-seq-cst" COMPILER_SUPPORTS_WATOMIC) if(COMPILER_SUPPORTS_WATOMIC) - add_compile_options(-Watomic-implicit-seq-cst) + add_compile_options("$<$:-Watomic-implicit-seq-cst>") endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8458987b5..ae910a84e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,11 +30,13 @@ include(sanitizer) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_CXX_STANDARD 11) if(MSVC) add_compile_options("/W3") else() - add_compile_options( + + set(c_flags -Wall -Wbad-function-cast -Wcast-align @@ -49,10 +51,14 @@ else() -Wuninitialized -Wvla ) + + add_compile_options( + "$<$:${c_flags}>" + ) endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wshorten-64-to-32) + add_compile_options("$<$:-Wshorten-64-to-32>") endif() include_directories( @@ -153,6 +159,8 @@ if(USE_OPENSSL) ) endif() +list(APPEND SRCS cplusplus.cpp) + ############################################################################## # diff --git a/test/cplusplus.cpp b/test/cplusplus.cpp new file mode 100644 index 000000000..8c79a3d6f --- /dev/null +++ b/test/cplusplus.cpp @@ -0,0 +1,25 @@ +/** + * @file cplusplus.cpp Emulate C++ applications + * + * Copyright (C) 2025 Alfred E. Heggestad + */ + +#include +#include +#include +#include "test.h" + + +#define DEBUG_MODULE "cplusplus" +#define DEBUG_LEVEL 5 +#include + + +int test_cplusplus(void) +{ + std::cout << "test\n"; + + DEBUG_NOTICE("%H\n", sys_kernel_get, nullptr); + + return 0; +} diff --git a/test/test.c b/test/test.c index 9be0c7bc0..0de8cabc7 100644 --- a/test/test.c +++ b/test/test.c @@ -279,6 +279,7 @@ static const struct test tests_integration[] = { TEST(test_tmr_jiffies_usec), TEST(test_turn_thread), TEST(test_thread_cnd_timedwait), + TEST(test_cplusplus), }; diff --git a/test/test.h b/test/test.h index ef4f8626c..129922eb2 100644 --- a/test/test.h +++ b/test/test.h @@ -388,6 +388,16 @@ int test_integration(const char *name, bool verbose); int test_sipevent_network(void); int test_sip_drequestf_network(void); +#ifdef __cplusplus +extern "C" { +#endif + +int test_cplusplus(void); + +#ifdef __cplusplus +} +#endif + /* High-level API */ int test_reg(const char *name, bool verbose); int test_oom(const char *name, bool verbose);