Skip to content

Commit 470180d

Browse files
committed
correct [[noreturn]]
1 parent 293ca0c commit 470180d

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

src/error/lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <stdlib.h>
22

3-
_Noreturn void err_c(int code){
3+
void err_c(int code){
44
exit(code);
55
}

src/error/lib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <cstdlib>
22

3-
extern "C" [[ noreturn ]] void err_cpp(int);
3+
#include "my_error.h"
44

5-
[[ noreturn ]] void err_cpp(int code){
5+
void err_cpp(int code){
66
exit(code);
77
}

src/error/my_error.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22
extern "C" {
33
#endif
44

5+
#if !defined(__has_c_attribute)
6+
# define __has_c_attribute(x) 0
7+
#endif
8+
9+
#if __has_c_attribute(noreturn)
10+
[[noreturn]]
11+
#elif __has_c_attribute(_Noreturn)
12+
[[_Noreturn]]
13+
#endif
514
void err_c(int);
15+
16+
#if __has_cpp_attribute(noreturn)
17+
[[noreturn]]
18+
#endif
619
void err_cpp(int);
20+
721
void error_fortran(int*);
822

923
#ifdef __cplusplus

test/error/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ add_test(NAME C++_Fortran_error
1616
COMMAND ${CMAKE_COMMAND} -Dexe=$<TARGET_FILE:cxx_fortran_error> -Dexp_code=42 -P ${PROJECT_SOURCE_DIR}/cmake/test_error.cmake
1717
)
1818

19-
add_executable(fortran_cxx_error error_cpp.f90 ${PROJECT_SOURCE_DIR}/src/error/lib.cpp)
20-
set_property(TARGET fortran_cxx_error PROPERTY LINKER_LANGUAGE Fortran)
19+
#object library for Visual Studio
20+
add_library(cpp_err OBJECT ${PROJECT_SOURCE_DIR}/src/error/lib.cpp)
21+
add_executable(fortran_cxx_error error_cpp.f90 $<TARGET_OBJECTS:cpp_err>)
22+
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
23+
set_property(TARGET fortran_cxx_error PROPERTY LINKER_LANGUAGE Fortran)
24+
endif()
2125
add_test(NAME Fortran_C++_error
2226
COMMAND ${CMAKE_COMMAND} -Dexe=$<TARGET_FILE:fortran_cxx_error> -Dexp_code=42 -P ${PROJECT_SOURCE_DIR}/cmake/test_error.cmake
2327
)
2428

25-
add_executable(fortran_c_error error_c.f90 ${PROJECT_SOURCE_DIR}/src/error/lib.c)
29+
add_library(c_err OBJECT ${PROJECT_SOURCE_DIR}/src/error/lib.c)
30+
add_executable(fortran_c_error error_c.f90 $<TARGET_OBJECTS:c_err>)
2631
add_test(NAME Fortran_C_error
2732
COMMAND ${CMAKE_COMMAND} -Dexe=$<TARGET_FILE:fortran_c_error> -Dexp_code=42 -P ${PROJECT_SOURCE_DIR}/cmake/test_error.cmake
2833
)

0 commit comments

Comments
 (0)