Skip to content

Commit 6079cbd

Browse files
committed
nullptr c23
1 parent 1085779 commit 6079cbd

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.25...4.2)
1+
cmake_minimum_required(VERSION 3.25...4.4)
22
# 3.19 for CheckSourceCompiles
33
# 3.25 for block()
44

test/nullptr/CMakeLists.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
set_property(DIRECTORY PROPERTY LABELS nullptr)
22

3+
block()
4+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
5+
set(CMAKE_C_STANDARD 23)
6+
# test has nullptr_t otherwise you're testing for a macro but not the type
7+
check_source_compiles(C "#include <stddef.h>
8+
nullptr_t p = nullptr;"
9+
c23_nullptr
10+
)
11+
endblock()
12+
13+
if(c23_nullptr)
314
add_library(c_nullptr OBJECT lib.c)
4-
target_include_directories(c_nullptr PRIVATE .)
15+
target_include_directories(c_nullptr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
16+
target_compile_features(c_nullptr PRIVATE c_std_23)
17+
endif()
18+
519
add_library(cpp_nullptr OBJECT lib.cpp)
6-
target_include_directories(cpp_nullptr PRIVATE .)
20+
target_include_directories(cpp_nullptr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
721

22+
if(TARGET c_nullptr)
823
add_executable(C_Fortran_nullptr main.f90 $<TARGET_OBJECTS:c_nullptr>)
924
add_test(NAME C_Nullptr COMMAND C_Fortran_nullptr)
25+
endif()
1026

1127
add_executable(Cpp_Fortran_nullptr main.f90 $<TARGET_OBJECTS:cpp_nullptr>)
1228
set_property(TARGET Cpp_Fortran_nullptr PROPERTY LINKER_LANGUAGE ${linker_lang})

test/nullptr/lib.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
#include <nullptr.h>
21
#include <stddef.h>
32

3+
#if __STDC_VERSION__ < 202311L
4+
#include <stdbool.h>
5+
#endif
6+
47
const char* nullchar(bool b) {
5-
return b ? NULL : "hello";
8+
return b ? nullptr : "hello";
69
}

0 commit comments

Comments
 (0)