mirror of
https://github.com/esphome/esphome.git
synced 2026-09-14 00:28:39 +00:00
address bot comments
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user