I just looked very quickly at the implementation of dyn_cast and isa in the LLVM documentation.
The code instance has the following:
struct bar { bar() {} private: bar(const bar &); }; struct foo { void ext() const; }; template <> inline bool isa_impl<foo,bar>(const bar &Val) { errs() << "Classof: " << &Val << "\n"; return true; }
The test is called using B and has:
if (!isa<foo>(B1)) return; if (!isa<foo>(B2)) return;
If I understand correctly what is going on correctly, the isa template (which is used by dyn_cast ) uses the explicit specialization of isa_impl to reference the panel with foo. In the above examples, it seems that isa<foo>(B1) returns true!
In any case, this is very different from the dynamic_cast behavior, so I really don't think you can compare them with each other.
Obviously, I can misunderstand what LLVM does, so please let me know if I do not understand the code!
Richard Corden
source share