diff --git a/mbo/types/internal/struct_names_clang.h b/mbo/types/internal/struct_names_clang.h index 756ca09..48e3e5f 100644 --- a/mbo/types/internal/struct_names_clang.h +++ b/mbo/types/internal/struct_names_clang.h @@ -71,6 +71,8 @@ class StructMetaBase { constexpr Storage() noexcept { if constexpr (std::is_default_constructible_v) { std::construct_at(&storage_.value); + } else { + memset(&storage_.value, 0, sizeof(T)); } } diff --git a/mbo/types/internal/struct_names_test.cc b/mbo/types/internal/struct_names_test.cc index 00f5a9f..298efc3 100644 --- a/mbo/types/internal/struct_names_test.cc +++ b/mbo/types/internal/struct_names_test.cc @@ -71,6 +71,10 @@ struct DefaultConstructorDeleted { static_assert(!std::is_default_constructible_v); static_assert(SupportsFieldNames); +# 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; @@ -83,6 +87,7 @@ TEST_F(StructNamesTest, StructWithoutDefaultConstructor) { // This cannot be done at compile time. EXPECT_THAT(GetFieldNames(), ElementsAre("ref", "val")); } +# endif // IS_CLANGD struct NoDestructor { // NOLINT(*-special-member-functions) constexpr NoDestructor() = default;