Skip to content

Commit

Permalink
Removed undefined use of union in getAnyPtr
Browse files Browse the repository at this point in the history
The use of cast generates the exact same assembler code.
  • Loading branch information
Dr15Jones committed Aug 27, 2021
1 parent fd2a236 commit 3a45d60
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions FWCore/Utilities/interface/getAnyPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@

namespace edm {
template <typename T>
inline std::unique_ptr<T> getAnyPtr(void* p, int offset) {
// A union is used to avoid possible copies during the triple cast that would otherwise be needed.
// std::unique_ptr<T> edp(static_cast<T*>(static_cast<void *>(static_cast<unsigned char *>(p) + offset)));
union {
void* vp;
unsigned char* ucp;
T* tp;
} pointerUnion;
assert(p != nullptr);
pointerUnion.vp = p;
pointerUnion.ucp += offset;
return std::unique_ptr<T>(pointerUnion.tp);
inline std::unique_ptr<T> getAnyPtr(void *p, int offset) {
return std::unique_ptr<T>(static_cast<T *>(static_cast<void *>(static_cast<unsigned char *>(p) + offset)));
}
} // namespace edm

Expand Down

0 comments on commit 3a45d60

Please sign in to comment.