diff --git a/src/cata_compiler_support.h b/src/cata_compiler_support.h new file mode 100644 index 0000000000000..a42c9ec917467 --- /dev/null +++ b/src/cata_compiler_support.h @@ -0,0 +1,18 @@ +#pragma once + +// Added due to clang 21.1 issue https://github.com/llvm/llvm-project/issues/154493 +#if defined(__clang__) && __clang_major__ == 21 && __clang_minor__ <= 1 +# define LAMBDA_NORETURN_CLANG21x1 __attribute__( ( noreturn ) ) +#else +# define LAMBDA_NORETURN_CLANG21x1 +#endif + +// Added for MSVC optimizations +// ref: https://github.com/CleverRaven/Cataclysm-DDA/pull/75376 +#ifndef CATA_FORCEINLINE +# ifdef _MSC_VER +# define CATA_FORCEINLINE __forceinline +# else +# define CATA_FORCEINLINE inline __attribute__( ( always_inline ) ) +# endif +#endif // CATA_FORCEINLINE diff --git a/src/cata_inline.h b/src/cata_inline.h deleted file mode 100644 index 4eb25ef629902..0000000000000 --- a/src/cata_inline.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#ifndef CATA_SRC_CATA_INLINE_H -#define CATA_SRC_CATA_INLINE_H - -#ifndef CATA_FORCEINLINE -#ifdef _MSC_VER -#define CATA_FORCEINLINE __forceinline -#else -#define CATA_FORCEINLINE inline __attribute__((always_inline)) -#endif -#endif - -#endif // CATA_SRC_CATA_INLINE_H diff --git a/src/coordinates.h b/src/coordinates.h index 85ef8ebb1862b..495a9c5b82318 100644 --- a/src/coordinates.h +++ b/src/coordinates.h @@ -14,7 +14,7 @@ #include #include -#include "cata_inline.h" +#include "cata_compiler_support.h" #include "coords_fwd.h" // IWYU pragma: export #include "cuboid_rectangle.h" #include "debug.h" diff --git a/src/item_search.cpp b/src/item_search.cpp index 2f5d0bb1b54dd..39d26bcd8aca7 100644 --- a/src/item_search.cpp +++ b/src/item_search.cpp @@ -10,6 +10,7 @@ #include "avatar.h" #include "bodypart.h" +#include "cata_compiler_support.h" #include "cata_utility.h" #include "enums.h" #include "flag.h" @@ -37,7 +38,8 @@ static std::function< bool( const item & )> can_contain_filter( std::string_view std::string_view filter, Unit max, std::vector> units, std::function set_function ) { - auto const error = [hint, filter]( char const *, size_t /* offset */ ) { + // TODO: LAMBDA_NORETURN_CLANG21x1 can be replaced with [[noreturn]] once we switch to C++23 on all compilers + auto const error = [hint, filter]( char const *, size_t /* offset */ ) LAMBDA_NORETURN_CLANG21x1 { throw math::runtime_error( _( string_format( hint, filter ) ) ); }; // Start at max. On convert failure: results are empty and user knows it is unusable. diff --git a/src/math_parser.cpp b/src/math_parser.cpp index 5ffa0f4fea1e8..563e644c7274a 100644 --- a/src/math_parser.cpp +++ b/src/math_parser.cpp @@ -17,6 +17,7 @@ #include #include "cata_assert.h" +#include "cata_compiler_support.h" #include "cata_utility.h" #include "condition.h" #include "coordinates.h" @@ -838,7 +839,8 @@ void math_exp::math_exp_impl::new_func() { output.emplace( std::in_place_type_t(), std::move( params ), v ); }, - []( auto /* v */ ) + // TODO: LAMBDA_NORETURN_CLANG21x1 can be replaced with [[noreturn]] once we switch to C++23 on all compilers + []( auto /* v */ ) LAMBDA_NORETURN_CLANG21x1 { throw math::internal_error( "Internal func error. That's all we know." ); }, @@ -975,7 +977,8 @@ void math_exp::math_exp_impl::new_oper() type = math_type_t::assign; output.emplace( std::in_place_type_t(), lhs, mhs, rhs, v->f ); }, - []( auto /* v */ ) + // TODO: LAMBDA_NORETURN_CLANG21x1 can be replaced with [[noreturn]] once we switch to C++23 on all compilers + []( auto /* v */ ) LAMBDA_NORETURN_CLANG21x1 { // we should never get here due to paren validation throw math::internal_error( "Internal oper error. That's all we know." ); diff --git a/src/math_parser_diag.cpp b/src/math_parser_diag.cpp index e186e8cdc305d..73ce7edcc16c4 100644 --- a/src/math_parser_diag.cpp +++ b/src/math_parser_diag.cpp @@ -13,6 +13,7 @@ #include "bodypart.h" #include "calendar.h" +#include "cata_compiler_support.h" #include "cata_utility.h" #include "character.h" #include "character_id.h" @@ -101,7 +102,8 @@ constexpr std::string_view _str_type_of() template T _read_from_string( std::string_view s, const std::vector> &units ) { - auto const error = [s]( char const * suffix, size_t /* offset */ ) { + // TODO: LAMBDA_NORETURN_CLANG21x1 can be replaced with [[noreturn]] once we switch to C++23 on all compilers + auto const error = [s]( char const * suffix, size_t /* offset */ ) LAMBDA_NORETURN_CLANG21x1 { throw math::runtime_error( R"(Failed to convert "%s" to a %s value: %s)", s, _str_type_of(), suffix ); }; diff --git a/src/recipe_dictionary.cpp b/src/recipe_dictionary.cpp index 0b134ebc8536e..392bf03887aab 100644 --- a/src/recipe_dictionary.cpp +++ b/src/recipe_dictionary.cpp @@ -15,6 +15,7 @@ #include "bodypart.h" #include "calendar.h" #include "cata_algo.h" +#include "cata_compiler_support.h" #include "cata_utility.h" #include "crafting_gui.h" #include "debug.h" @@ -215,7 +216,8 @@ template static Unit can_contain_filter( std::string_view hint, std::string_view txt, Unit max, std::vector> units ) { - auto const error = [hint, txt]( char const *, size_t /* offset */ ) { + // TODO: LAMBDA_NORETURN_CLANG21x1 can be replaced with [[noreturn]] once we switch to C++23 on all compilers + auto const error = [hint, txt]( char const *, size_t /* offset */ ) LAMBDA_NORETURN_CLANG21x1 { throw math::runtime_error( _( string_format( hint, txt ) ) ); }; // Start at max. On convert failure: results are empty and user knows it is unusable.