[base] Fix undefined behaviour in LazyInstanceImpl.
Patch from Thomas Köppe <tkoeppe@google.com>. Change-Id: I7ae2e001b6bd72ad67baad64d35e7c17d4ed4716 Reviewed-on: https://chromium-review.googlesource.com/806221 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#49838}
This commit is contained in:
parent
03b4d39133
commit
e4866b94e1
@ -168,17 +168,13 @@ struct LazyInstanceImpl {
|
|||||||
typedef typename AllocationTrait::StorageType StorageType;
|
typedef typename AllocationTrait::StorageType StorageType;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void InitInstance(StorageType* storage) {
|
static void InitInstance(void* storage) {
|
||||||
AllocationTrait::template InitStorageUsingTrait<CreateTrait>(storage);
|
AllocationTrait::template InitStorageUsingTrait<CreateTrait>(
|
||||||
|
static_cast<StorageType*>(storage));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init() const {
|
void Init() const {
|
||||||
InitOnceTrait::Init(
|
InitOnceTrait::Init(&once_, &InitInstance, static_cast<void*>(&storage_));
|
||||||
&once_,
|
|
||||||
// Casts to void* are needed here to avoid breaking strict aliasing
|
|
||||||
// rules.
|
|
||||||
reinterpret_cast<void(*)(void*)>(&InitInstance), // NOLINT
|
|
||||||
reinterpret_cast<void*>(&storage_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user