StoredDeclsList::setOnlyValue wants to assert that the binary value
actually stored in the member PointerUnion Data is the same as the raw
NamedDecl pointer argument. However the way in which it was checking
this involved a cast which created a type-punned pointer, and
dereferencing that pointer broke strict aliasing rules.
I have a build of clang by gcc where gcc emitted code to read from the
pointer for the assert before writing to it and so caused the assertion
to fail.
I'm not sure this is the best alternative formulation for the assert.
Please feel free to suggest another spelling as appropriate.
Hm, I don't have much experience with the PointerUnion class, but from a cursory look at llvm/include/llvm/ADT/PointerUnion.h, I would rather say that using dyn_cast here would be more appropriate? E.g. that definition literally says:
So something like:
or even using the existing getAsDecl member function, which does exactly the same:
Or is this particular check about the type being *only* the base class NamedDecl, and not any derived class?