Skip to content

Commit 4d57b2e

Browse files
authored
Merge pull request intel#180 from elbeno/add-flatten
✨ Add `flatten` attribute
2 parents 39f3dfc + aae025a commit 4d57b2e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

include/stdx/compiler.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
#endif
2323
#endif
2424

25+
#ifndef USING_ATTR_NS
26+
#if defined(__clang__)
27+
#define USING_ATTR_NS using clang:
28+
#else
29+
#define USING_ATTR_NS using gnu:
30+
#endif
31+
#endif
32+
2533
#ifndef ALWAYS_INLINE
2634
#define ALWAYS_INLINE inline __attribute__((always_inline))
2735
#endif
@@ -30,6 +38,10 @@
3038
#define NEVER_INLINE __attribute__((noinline))
3139
#endif
3240

41+
#ifndef FLATTEN
42+
#define FLATTEN __attribute__((flatten))
43+
#endif
44+
3345
#ifndef MUSTTAIL
3446
#if defined(__clang__)
3547
#define MUSTTAIL [[clang::musttail]]

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ add_tests(
3131
byterator
3232
cached
3333
callable
34+
compiler
3435
concepts
3536
conditional
3637
ct_conversions

test/compiler.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdx/compiler.hpp>
2+
3+
#include <catch2/catch_test_macros.hpp>
4+
5+
TEST_CASE("using attribute namespace", "[compiler]") {
6+
[[USING_ATTR_NS warn_unused_result]] auto f(int) -> int;
7+
}
8+
9+
ALWAYS_INLINE auto f1(int) -> void;
10+
11+
TEST_CASE("NEVER_INLINE", "[compiler]") { NEVER_INLINE auto f2(int) -> void; }
12+
13+
TEST_CASE("FLATTEN", "[compiler]") { FLATTEN auto f3(int) -> void; }
14+
15+
ALWAYS_INLINE FLATTEN auto f4(int) -> void;

0 commit comments

Comments
 (0)