Skip to content

Commit

Permalink
Merge pull request #35051 from Dr15Jones/noUnion_getAnyPtr
Browse files Browse the repository at this point in the history
Removed undefined use of union in getAnyPtr
  • Loading branch information
cmsbuild authored Aug 30, 2021
2 parents 209b393 + 3a45d60 commit 60eb2fb
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 60eb2fb

Please sign in to comment.