카테고리 없음

fno-exceptions 에서 STL 동작 테스트

newpolaris 2019. 6. 22. 16:50

https://stackoverflow.com/questions/7249378/disabling-c-exceptions-how-can-i-make-any-std-throw-immediately-terminate

의외로 간단한 결론이 있다

머리가 안돌아갔나봄

abort 시킨다고 해서 실제로 실험해보니

$ ls -al a.out 
-rwxr-xr-x  1 newpolaris  wheel  26152 Jun 27 00:55 a.out*

newpolaris@Donghyuns-MacBook-Pro : /tmp
$ g++ test.cpp -fno-exceptions

newpolaris@Donghyuns-MacBook-Pro : /tmp
$ ls -al a.out 
-rwxr-xr-x  1 newpolaris  wheel  20800 Jun 27 00:55 a.out*

사이즈도 안줄고, exception도 나는데?

$ g++ test.cpp -fno-exceptions && ./a.out 
libc++abi.dylib: terminating with uncaught exception of type std::length_error: vector
Abort trap: 6

Unfortunately the part about "-fno-exception" removing all exception handling code and turning all throws into aborts is wrong. Well - partially wrong. This is true when you compile the library in question (libstdc++v3) with this flag

newpolaris@Donghyuns-MacBook-Pro : /tmp
$ g++ test.cpp -fno-exceptions
test.cpp:9:5: error: cannot use 'try' with exceptions disabled
    try {
    ^
1 error generated.

그러하다.