[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:
Ulan Degenbaev 2017-12-04 16:52:55 +01:00 committed by Commit Bot
parent 03b4d39133
commit e4866b94e1

View File

@ -168,17 +168,13 @@ struct LazyInstanceImpl {
typedef typename AllocationTrait::StorageType StorageType;
private:
static void InitInstance(StorageType* storage) {
AllocationTrait::template InitStorageUsingTrait<CreateTrait>(storage);
static void InitInstance(void* storage) {
AllocationTrait::template InitStorageUsingTrait<CreateTrait>(
static_cast<StorageType*>(storage));
}
void Init() const {
InitOnceTrait::Init(
&once_,
// Casts to void* are needed here to avoid breaking strict aliasing
// rules.
reinterpret_cast<void(*)(void*)>(&InitInstance), // NOLINT
reinterpret_cast<void*>(&storage_));
InitOnceTrait::Init(&once_, &InitInstance, static_cast<void*>(&storage_));
}
public: