From aae025a948f73e428846c7fa60ada5c4d9ef80cc Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Tue, 31 Dec 2024 14:40:33 -0700 Subject: [PATCH] :sparkles: Add `flatten` attribute --- include/stdx/compiler.hpp | 12 ++++++++++++ test/CMakeLists.txt | 1 + test/compiler.cpp | 15 +++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 test/compiler.cpp diff --git a/include/stdx/compiler.hpp b/include/stdx/compiler.hpp index 80760d7..05e723a 100644 --- a/include/stdx/compiler.hpp +++ b/include/stdx/compiler.hpp @@ -22,6 +22,14 @@ #endif #endif +#ifndef USING_ATTR_NS +#if defined(__clang__) +#define USING_ATTR_NS using clang: +#else +#define USING_ATTR_NS using gnu: +#endif +#endif + #ifndef ALWAYS_INLINE #define ALWAYS_INLINE inline __attribute__((always_inline)) #endif @@ -30,6 +38,10 @@ #define NEVER_INLINE __attribute__((noinline)) #endif +#ifndef FLATTEN +#define FLATTEN __attribute__((flatten)) +#endif + #ifndef MUSTTAIL #if defined(__clang__) #define MUSTTAIL [[clang::musttail]] diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5d71cc8..6cf74f2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,6 +31,7 @@ add_tests( byterator cached callable + compiler concepts conditional ct_conversions diff --git a/test/compiler.cpp b/test/compiler.cpp new file mode 100644 index 0000000..1ac18b7 --- /dev/null +++ b/test/compiler.cpp @@ -0,0 +1,15 @@ +#include + +#include + +TEST_CASE("using attribute namespace", "[compiler]") { + [[USING_ATTR_NS warn_unused_result]] auto f(int) -> int; +} + +ALWAYS_INLINE auto f1(int) -> void; + +TEST_CASE("NEVER_INLINE", "[compiler]") { NEVER_INLINE auto f2(int) -> void; } + +TEST_CASE("FLATTEN", "[compiler]") { FLATTEN auto f3(int) -> void; } + +ALWAYS_INLINE FLATTEN auto f4(int) -> void;