VTK
vtkAssume.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAssume.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
20 #ifndef vtkAssume_h
21 #define vtkAssume_h
22 
23 #include "vtkConfigure.h"
24 
25 #include <cassert>
26 
42 #define VTK_ASSUME(cond) \
43  do { \
44  const bool c = cond; \
45  assert("Bad assumption in VTK_ASSUME: " #cond && c); \
46  VTK_ASSUME_IMPL(c); \
47  (void)c; /* Prevents unused var warnings */ \
48  } while (false) /* do-while prevents extra semicolon warnings */
49 
50 // VTK_ASSUME_IMPL is compiler-specific:
51 #if defined(VTK_COMPILER_MSVC) || defined(VTK_COMPILER_ICC)
52 # define VTK_ASSUME_IMPL(cond) __assume(cond)
53 #elif defined(VTK_COMPILER_GCC) && VTK_COMPILER_GCC_VERSION >= 40500
54 // Added in 4.5.0:
55 # define VTK_ASSUME_IMPL(cond) if (!(cond)) __builtin_unreachable()
56 #elif defined(VTK_COMPILER_CLANG)
57 # define VTK_ASSUME_IMPL(cond) if (!(cond)) __builtin_unreachable()
58 #else
59 # define VTK_ASSUME_IMPL(cond) do {} while (false) /* no-op */
60 #endif
61 
62 #endif // vtkAssume_h
63 // VTK-HeaderTest-Exclude: vtkAssume.h