VTK  9.3.20240426
vtkAssume.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
8#ifndef vtkAssume_h
9#define vtkAssume_h
10
11#include "vtkCompiler.h"
12
13#include <cassert>
14
30#define VTK_ASSUME(cond) \
31 do \
32 { \
33 const bool c = cond; \
34 assert("Bad assumption in VTK_ASSUME: " #cond&& c); \
35 VTK_ASSUME_IMPL(c); \
36 (void)c; /* Prevents unused var warnings */ \
37 } while (false) /* do-while prevents extra semicolon warnings */
38
39#define VTK_ASSUME_NO_ASSERT(cond) \
40 do \
41 { \
42 const bool c = cond; \
43 VTK_ASSUME_IMPL(c); \
44 (void)c; /* Prevents unused var warnings */ \
45 } while (false) /* do-while prevents extra semicolon warnings */
46
47// VTK_ASSUME_IMPL is compiler-specific:
48#if defined(VTK_COMPILER_MSVC) || defined(VTK_COMPILER_ICC)
49#define VTK_ASSUME_IMPL(cond) __assume(cond)
50#elif defined(VTK_COMPILER_GCC) || defined(VTK_COMPILER_CLANG)
51#define VTK_ASSUME_IMPL(cond) \
52 if (!(cond)) \
53 __builtin_unreachable()
54#else
55#define VTK_ASSUME_IMPL(cond) \
56 do \
57 { \
58 } while (false) /* no-op */
59#endif
60
61#endif // vtkAssume_h
62// VTK-HeaderTest-Exclude: vtkAssume.h