Skip to content

Commit 36bfc22

Browse files
fix
1 parent ef900d7 commit 36bfc22

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

libc/src/__support/CPP/type_traits/has_unique_object_representations.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_HAS_UNIQUE_OBJECT_REPRESENTATIONS_H
1010

1111
#include "src/__support/CPP/type_traits/integral_constant.h"
12+
#include "src/__support/CPP/type_traits/remove_all_extents.h"
1213
#include "src/__support/macros/config.h"
1314

1415
namespace LIBC_NAMESPACE_DECL {
1516
namespace cpp {
1617

1718
template <class T>
1819
struct has_unique_object_representations
19-
: public integral_constant<bool, __has_unique_object_representations(T)> {};
20+
: public integral_constant<bool, __has_unique_object_representations(
21+
remove_all_extents_t<T>)> {};
2022

2123
template <class T>
2224
LIBC_INLINE_VAR constexpr bool has_unique_object_representations_v =

libc/test/src/__support/CPP/type_traits_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,28 @@ TEST(LlvmLibcTypeTraitsTest, is_object) {
439439

440440
TEST(LlvmLibcTypeTraitsTest, true_type) { EXPECT_TRUE((true_type::value)); }
441441

442+
struct CompilerLeadingPadded {
443+
char b;
444+
int a;
445+
};
446+
447+
struct CompilerTrailingPadded {
448+
int a;
449+
char b;
450+
};
451+
452+
struct alignas(long long) ManuallyPadded {
453+
int b;
454+
char padding[sizeof(long long) - sizeof(int)];
455+
};
456+
457+
TEST(LlvmLibcTypeTraitsTest, has_unique_object_representations) {
458+
EXPECT_TRUE(has_unique_object_representations<int>::value);
459+
EXPECT_FALSE(has_unique_object_representations_v<CompilerLeadingPadded>);
460+
EXPECT_FALSE(has_unique_object_representations_v<CompilerTrailingPadded>);
461+
EXPECT_TRUE(has_unique_object_representations_v<ManuallyPadded>);
462+
}
463+
442464
// TODO type_identity
443465

444466
// TODO void_t

0 commit comments

Comments
 (0)