Skip to content

Commit

Permalink
The clangd indexer takes aim at how field names are looked up from …
Browse files Browse the repository at this point in the history
…uninitialized

// memory and reliably crashes here. So this piece is disabled for the indexer.
  • Loading branch information
helly25 committed Nov 23, 2024
1 parent 2983e92 commit 0ed33f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mbo/types/internal/struct_names_clang.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class StructMetaBase {
constexpr Storage() noexcept {
if constexpr (std::is_default_constructible_v<T>) {
std::construct_at(&storage_.value);
} else {
memset(&storage_.value, 0, sizeof(T));
}
}

Expand Down
5 changes: 5 additions & 0 deletions mbo/types/internal/struct_names_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ struct DefaultConstructorDeleted {
static_assert(!std::is_default_constructible_v<DefaultConstructorDeleted>);
static_assert(SupportsFieldNames<DefaultConstructorDeleted>);

# ifndef IS_CLANGD
// The indexer takes aim at how field names are `looked up` from uninitialized
// memory and reliably crashes here. So this piece is disabled for the indexer.

struct NoDefaultConstructor {
int& ref;
int val;
Expand All @@ -83,6 +87,7 @@ TEST_F(StructNamesTest, StructWithoutDefaultConstructor) {
// This cannot be done at compile time.
EXPECT_THAT(GetFieldNames<NoDefaultConstructor>(), ElementsAre("ref", "val"));
}
# endif // IS_CLANGD

struct NoDestructor { // NOLINT(*-special-member-functions)
constexpr NoDestructor() = default;
Expand Down

0 comments on commit 0ed33f0

Please sign in to comment.