File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 362362
363363#endif // NAZARA_NO_LIKELY_ATTRIBUTE
364364
365+ // Unreachable macro
366+ #ifndef NAZARA_NO_UNREACHABLE_MACRO
367+
368+ #if defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
369+ #define NAZARA_UNREACHABLE () __builtin_unreachable()
370+ #elif defined(NAZARA_COMPILER_MSVC)
371+ #define NAZARA_UNREACHABLE () __assume(false )
372+ #endif
373+
374+ #endif // NAZARA_NO_UNREACHABLE_MACRO
375+
376+ // Fallbacks
377+
365378#ifndef NAZARA_ASSUME
366379 #define NAZARA_ASSUME (expr )
367380#endif
378391 #define NAZARA_UNLIKELY (expr ) (expr)
379392#endif
380393
394+ #ifndef NAZARA_UNREACHABLE
395+ #define NAZARA_UNREACHABLE () throw Nz::UnreachableError{};
396+ #endif
397+
381398// Detect arch
382399#ifndef NAZARA_NO_ARCH_DETECTION
383400
@@ -467,6 +484,8 @@ namespace Nz
467484
468485 using Int64 = int64_t ;
469486 using UInt64 = uint64_t ;
487+
488+ struct UnreachableError {};
470489}
471490
472491#endif // NAZARAUTILS_PREREQUISITES_HPP
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ NAZARA_FORCEINLINE float sqrtCheck(float x)
1010 if NAZARA_UNLIKELY (x < 0 )
1111 {
1212 throw std::runtime_error (" square root of negative value" );
13+
14+ NAZARA_UNREACHABLE ();
1315 }
1416
1517 NAZARA_ASSUME (x != 0 .f );
You can’t perform that action at this time.
0 commit comments