Advanced Multi-Physics (AMP)
On-Line Documentation
UtilityMacros.h
Go to the documentation of this file.
1// This file contains useful macros including AMP_ERROR, AMP_WARNING, AMP_INSIST, AMP_ASSERT, etc.
2#ifndef included_AMP_UtilityMacros
3#define included_AMP_UtilityMacros
4
5#include <sstream>
6#include <string_view>
7
8#include "StackTrace/source_location.h"
9
10
11// Forward declare StackTrace abort
13[[noreturn]] void abort( const std::string &message, const source_location &source );
14}
15
16
17// Forward declare stream operators
18namespace AMP {
19extern std::ostream pout;
20extern std::ostream perr;
21extern std::ostream plog;
22} // namespace AMP
23
24
25template<class T>
26inline constexpr bool failed_assert_v = !std::is_same<T, T>::value;
27
28
29// Overload some operators for string_view for convience
30namespace AMP {
31template<std::size_t N>
32static inline std::string operator+( char x[N], std::string_view y )
33{
34 return std::string( x ) + std::string( y );
35}
36template<std::size_t N>
37static inline std::string operator+( std::string_view y, char x[N] )
38{
39 return std::string( x ) + std::string( y );
40}
41static inline std::string operator+( std::string_view x, std::string_view y )
42{
43 return std::string( x ) + std::string( y );
44}
45} // namespace AMP
46
47
61#undef STATIC_ERROR
62#define STATIC_ERROR( MSG ) static_assert( failed_assert_v<TYPE>, MSG )
63
64
72#define AMP_ERROR( MSG ) StackTrace::Utilities::abort( MSG, SOURCE_LOCATION_CURRENT() )
73
74
80#define AMP_WARNING( MSG ) \
81 do { \
82 AMP::pout << "WARNING: " << MSG << std::endl; \
83 AMP::plog << "WARNING: " << MSG << std::endl; \
84 AMP::pout << " Warning called in " << __FILE__ << " on line " << __LINE__ << std::endl; \
85 AMP::plog << " Warning called in " << __FILE__ << " on line " << __LINE__ << std::endl; \
86 AMP::plog << std::flush; \
87 } while ( 0 )
88
89
96#define AMP_WARN_ONCE( MSG ) \
97 do { \
98 static bool printed = false; \
99 if ( !printed ) { \
100 AMP_WARNING( MSG ); \
101 printed = true; \
102 } \
103 } while ( 0 )
104
105
114#define AMP_ASSERT( EXP ) \
115 do { \
116 if ( !( EXP ) ) { \
117 StackTrace::Utilities::abort( "Failed assertion: " #EXP, SOURCE_LOCATION_CURRENT() ); \
118 } \
119 } while ( 0 )
120
121
131#define AMP_INSIST( EXP, MSG ) \
132 do { \
133 if ( !( EXP ) ) { \
134 StackTrace::Utilities::abort( "Failed insist: " #EXP "\nMessage: " + \
135 std::string( MSG ), \
136 SOURCE_LOCATION_CURRENT() ); \
137 } \
138 } while ( 0 )
139
140
141// Macros for use when assertions are to be included only when debugging.
160#if ( defined( DEBUG ) || defined( _DEBUG ) ) && !defined( NDEBUG )
161 #define AMP_DEBUG_ASSERT( EXP ) AMP_ASSERT( EXP )
162 #define AMP_DEBUG_INSIST( EXP, MSG ) AMP_INSIST( EXP, MSG )
163 #define AMP_DEBUG
164#else
165 #define AMP_DEBUG_ASSERT( EXP ) \
166 do { \
167 } while ( 0 )
168 #define AMP_DEBUG_INSIST( EXP, MSG ) \
169 do { \
170 } while ( 0 )
171#endif
172
173
174// clang-format off
175
185#ifndef DISABLE_WARNINGS
186 #if defined( _MSC_VER )
187 #define DISABLE_WARNINGS
188 #define ENABLE_WARNINGS
189 #elif defined( __clang__ )
190 #define DISABLE_WARNINGS \
191 _Pragma( "clang diagnostic push" ) \
192 _Pragma( "clang diagnostic ignored \"-Wall\"" ) \
193 _Pragma( "clang diagnostic ignored \"-Wextra\"" ) \
194 _Pragma( "clang diagnostic ignored \"-Wunused-private-field\"" ) \
195 _Pragma( "clang diagnostic ignored \"-Wdeprecated-declarations\"" ) \
196 _Pragma( "clang diagnostic ignored \"-Winteger-overflow\"" ) \
197 _Pragma( "clang diagnostic ignored \"-Winconsistent-missing-override\"" ) \
198 _Pragma( "clang diagnostic ignored \"-Wimplicit-int-float-conversion\"" )
199 #define ENABLE_WARNINGS _Pragma( "clang diagnostic pop" )
200 #elif defined( __INTEL_COMPILER )
201 #if defined ( __INTEL_LLVM_COMPILER )
202 // have to figure these warnings out
203 #define DISABLE_WARNINGS \
204 _Pragma( "warning (push)" ) \
205 _Pragma( "clang diagnostic ignored \"-Wunused-lambda-capture\"" )
206 #define ENABLE_WARNINGS _Pragma( "warning(pop)" )
207 #else
208 #define DISABLE_WARNINGS \
209 _Pragma( "warning (push)" ) \
210 _Pragma( "warning disable 488" ) \
211 _Pragma( "warning disable 1011" ) \
212 _Pragma( "warning disable 61" ) \
213 _Pragma( "warning disable 1478" ) \
214 _Pragma( "warning disable 488" ) \
215 _Pragma( "warning disable 2651" )
216 #define ENABLE_WARNINGS _Pragma( "warning(pop)" )
217 #endif
218 #elif defined( __GNUC__ )
219 #define DISABLE_WARNINGS \
220 _Pragma( "GCC diagnostic push" ) \
221 _Pragma( "GCC diagnostic ignored \"-Wpragmas\"" ) \
222 _Pragma( "GCC diagnostic ignored \"-Wcpp\"" ) \
223 _Pragma( "GCC diagnostic ignored \"-Wall\"" ) \
224 _Pragma( "GCC diagnostic ignored \"-Wextra\"" ) \
225 _Pragma( "GCC diagnostic ignored \"-Wpedantic\"" ) \
226 _Pragma( "GCC diagnostic ignored \"-Wunused-local-typedefs\"" ) \
227 _Pragma( "GCC diagnostic ignored \"-Woverloaded-virtual\"" ) \
228 _Pragma( "GCC diagnostic ignored \"-Wunused-parameter\"" ) \
229 _Pragma( "GCC diagnostic ignored \"-Wdeprecated-copy\"" ) \
230 _Pragma( "GCC diagnostic ignored \"-Wdeprecated-declarations\"" ) \
231 _Pragma( "GCC diagnostic ignored \"-Wvirtual-move-assign\"" ) \
232 _Pragma( "GCC diagnostic ignored \"-Wunused-function\"" ) \
233 _Pragma( "GCC diagnostic ignored \"-Woverflow\"" ) \
234 _Pragma( "GCC diagnostic ignored \"-Wunused-variable\"" ) \
235 _Pragma( "GCC diagnostic ignored \"-Wignored-qualifiers\"" ) \
236 _Pragma( "GCC diagnostic ignored \"-Wenum-compare\"" ) \
237 _Pragma( "GCC diagnostic ignored \"-Wsign-compare\"" ) \
238 _Pragma( "GCC diagnostic ignored \"-Wterminate\"" ) \
239 _Pragma( "GCC diagnostic ignored \"-Wimplicit-fallthrough\"" ) \
240 _Pragma( "GCC diagnostic ignored \"-Wmaybe-uninitialized\"" ) \
241 _Pragma( "GCC diagnostic ignored \"-Winaccessible-base\"" ) \
242 _Pragma( "GCC diagnostic ignored \"-Wclass-memaccess\"" ) \
243 _Pragma( "GCC diagnostic ignored \"-Wcast-function-type\"" ) \
244 _Pragma( "GCC diagnostic ignored \"-Waggressive-loop-optimizations\"" )
245 #define ENABLE_WARNINGS _Pragma( "GCC diagnostic pop" )
246 #else
247 #define DISABLE_WARNINGS
248 #define ENABLE_WARNINGS
249 #endif
250#endif
251// clang-format on
252
255#endif
constexpr bool failed_assert_v
std::ostream plog
std::ostream perr
std::ostream pout
Array< TYPE, FUN, Allocator > operator+(const Array< TYPE, FUN, Allocator > &a, const Array< TYPE, FUN, Allocator > &b)
Definition Array.h:881
void abort(const std::string &message, const source_location &source)



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page