Skip to content

Commit

Permalink
Update aligned storage to avoid strict aliasing warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cmazakas committed Jan 8, 2024
1 parent 74d2510 commit 630e171
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/unit/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,14 @@ struct parser_test
template<class T>
class opt
{
unsigned char v_[
sizeof(T)];
union aligned_storage {
aligned_storage(){}
~aligned_storage(){}

T v_;
};

aligned_storage s_;
bool b_ = false;

public:
Expand Down Expand Up @@ -131,12 +137,12 @@ struct parser_test

T& get() noexcept
{
return *reinterpret_cast<T*>(v_);
return s_.v_;
}

T const& get() const noexcept
{
return *reinterpret_cast<T*>(v_);
return s_.v_;
}

T& operator*() noexcept
Expand Down

0 comments on commit 630e171

Please sign in to comment.