address bot comments

This commit is contained in:
J. Nick Koston
2026-03-22 11:34:27 -10:00
parent 478ac9d9f2
commit bc688b973a
2 changed files with 9 additions and 4 deletions
+5 -4
View File
@@ -2235,11 +2235,12 @@ template<class T> struct PlacementStorage {
/// @brief Raw byte storage, strictly aligned for type T.
alignas(T) unsigned char data[sizeof(T)];
/// @brief Retrieves a pointer to the constructed object.
T *get() { return std::launder(reinterpret_cast<T *>(data)); }
/// @brief Retrieves a pointer to the storage as the target type.
/// The caller must ensure the object has been constructed via placement new before dereferencing.
T *get() { return reinterpret_cast<T *>(data); }
/// @brief Retrieves a const pointer to the constructed object.
const T *get() const { return std::launder(reinterpret_cast<const T *>(data)); }
/// @brief Retrieves a const pointer to the storage as the target type.
const T *get() const { return reinterpret_cast<const T *>(data); }
};
/// @name Internal functions
@@ -118,6 +118,10 @@ def test_code_generation(
"""Test code generation for display."""
main_cpp = generate_main(component_fixture_path("mipi_dsi.yaml"))
assert (
"static esphome::PlacementStorage<mipi_dsi::MIPI_DSI> p4_nano_storage_;"
in main_cpp
)
assert (
"static mipi_dsi::MIPI_DSI *const p4_nano = p4_nano_storage_.get();" in main_cpp
)