c++ - Why does Clang returns sometimes nullptr, sometimes what I want? -
this question indirectly follows this question, in case want wider on want make.
so, basically, want distinguish handlers catching common classes, , handlers catching classes are, indeed, child classes.
so, previous provided link, found way know if i'm dealing simple class, or child class, but, can't cxxrecorddecl
of base associated child class.
for instance, here piece of code :
class b{ // implementation of class b }; class d : public b{ // implementation of class d }; int main(){ try{ // code try statement } catch(d & d){ // handler d } return 0; }
with following piece of code, able cxxrecorddecl
of class d
:
bool visitcxxtrystmt(cxxtrystmt * trystmt){ cxxrecorddecl * child_class = trystmt->gethandler(0)->getcaughttype().gettypeptr()->getpointeecxxrecorddecl(); return true; }
this works fine, can have cxxrecorddecl
through qualtype
. innocently thought work aswell base class :
bool visitcxxtrystmt(cxxtrystmt * trystmt){ cxxrecorddecl * base_class = trystmt->gethandler(0)->getcaughttype().gettypeptr()->getpointeecxxrecorddecl()->bases_begin()->gettype().gettypeptr()->getpointeecxxrecorddecl(); return true; }
but returns nullptr. however, if i'm executing line :
cout << trystmt->gethandler(0)->getcaughttype().gettypeptr()->getpointeecxxrecorddecl()->bases_begin()->gettype().getasstring() << endl;
i have output want (class b).
so, why can have class declaration in 1 case, not in other ??
i found method cxxrecorddecl
wanted.
i don't have plausible explanation that, :
- in first case, using method getpointeecxxrecorddecl returns wanted
cxxrecorddecl
. - in second case, using method getascxxrecorddecl returns wanted
cxxrecorddecl
.
these statements can not interchanged (using getascxxrecorddecl
in first case returns nullptr
whereas using getpointeecxxrecorddecl
in second case returns nullptr
.
i don't have explanation, work wanted to, if bothers me little not know why :/
Comments
Post a Comment