diff --git a/src/global/global.cpp b/src/global/global.cpp index ee1776922..65b35a83f 100644 --- a/src/global/global.cpp +++ b/src/global/global.cpp @@ -34,7 +34,7 @@ void Set_Gammas(Real gamma_in) { // set gamma gama = gamma_in; - ASSERT(gama > 1.0, "Set_Gammas", "Gamma must be greater than one."); + ASSERT(gama > 1.0, "Gamma must be greater than one."); } /*! \fn double get_time(void) diff --git a/src/io/io.cpp b/src/io/io.cpp index 9edf6c4b4..88e460e3b 100644 --- a/src/io/io.cpp +++ b/src/io/io.cpp @@ -2788,10 +2788,10 @@ void Ensure_Outdir_Exists(std::string outdir) // to a directory (it's unclear from docs whether err-code is set in that // case) if (err_code or not std::filesystem::is_directory(without_file_prefix)) { - ERROR("Ensure_Outdir_Exists", - "something went wrong while trying to create the path to the " - "output-dir: %s", - outdir.c_str()); + ERROR( + "something went wrong while trying to create the path to the " + "output-dir: %s", + outdir.c_str()); } } } diff --git a/src/utils/error_handling.cpp b/src/utils/error_handling.cpp index c64ee362b..04439c6c7 100644 --- a/src/utils/error_handling.cpp +++ b/src/utils/error_handling.cpp @@ -61,7 +61,7 @@ void Check_Configuration(parameters const& P) // Check the boundary conditions auto Check_Boundary = [](int const& boundary, std::string const& direction) { bool is_allowed_bc = boundary >= 0 and boundary <= 4; - ASSERT(is_allowed_bc, "Check_Configuration", + ASSERT(is_allowed_bc, "WARNING: Possibly invalid boundary conditions for direction: %s flag: %d. " "Must select between 0 (no boundary), 1 (periodic), 2 (reflective), 3 (transmissive), 4 (custom), 5 (mpi).", direction.c_str(), boundary); diff --git a/src/utils/error_handling.h b/src/utils/error_handling.h index 7fe450cba..2406b4f49 100644 --- a/src/utils/error_handling.h +++ b/src/utils/error_handling.h @@ -19,14 +19,27 @@ void Check_Configuration(parameters const& P); */ [[noreturn]] void Abort_With_Err_(const char* func_name, const char* file_name, int line_num, const char* msg, ...); +/* __CHOLLA_PRETTY_FUNC__ is a magic constant like __LINE__ or __FILE__ that + * provides the name of the current function. + * - The C++11 standard requires that __func__ is provided on all platforms, but + * that only provides limited information (just the name of the function). + * - Where available, we prefer to use compiler-specific features that provide + * more information about the function (like the scope of the function & the + * the function signature). + */ +#ifdef __GNUG__ + #define __CHOLLA_PRETTY_FUNC__ __PRETTY_FUNCTION__ +#else + #define __CHOLLA_PRETTY_FUNC__ __func__ +#endif + /*! * \brief print an error-message (with printf formatting) & abort the program. * * This macro should be treated as a function with the signature: - * [[noreturn]] void ERROR(const char* func_name, const char* msg, ...); + * [[noreturn]] void ERROR(const char* msg, ...); * - * - The 1st arg is the name of the function where it's called - * - The 2nd arg is printf-style format argument specifying the error message + * - The 1st arg is printf-style format argument specifying the error message * - The remaining args arguments are used to format error message * * \note @@ -34,26 +47,25 @@ void Check_Configuration(parameters const& P); * at least 1 variadic argument (even in cases when ``msg`` doesn't format * any arguments). There is no way around this until C++ 20. */ -#define ERROR(func_name, ...) Abort_With_Err_(func_name, __FILE__, __LINE__, __VA_ARGS__) +#define ERROR(...) Abort_With_Err_(__CHOLLA_PRETTY_FUNC__, __FILE__, __LINE__, __VA_ARGS__) /*! * \brief if the condition is false, print an error-message (with printf * formatting) & abort the program. * * This macro should be treated as a function with the signature: - * [[noreturn]] void ASSERT(bool cond, const char* func_name, const char* msg, ...); + * [[noreturn]] void ASSERT(bool cond, const char* msg, ...); * * - The 1st arg is a boolean condition. When true, this does noth - * - The 2nd arg is the name of the function where it's called - * - The 3rd arg is printf-style format argument specifying the error message + * - The 2nd arg is printf-style format argument specifying the error message * - The remaining args arguments are used to format error message * * \note * the behavior is independent of the ``NDEBUG`` macro */ -#define ASSERT(cond, func_name, ...) \ - if (not(cond)) { \ - Abort_With_Err_(func_name, __FILE__, __LINE__, __VA_ARGS__); \ +#define ASSERT(cond, ...) \ + if (not(cond)) { \ + Abort_With_Err_(__CHOLLA_PRETTY_FUNC__, __FILE__, __LINE__, __VA_ARGS__); \ } #endif /*ERROR_HANDLING_CHOLLA_H*/