David Come
2014-Feb-17 08:43 UTC
[LLVMdev] CXXMethodDecl::getNameAsString for template-class' constructor or destructor
Hello ! I'm writing a small software to translate header into C++ files. It works fine for non-template class but I'm having n issue with template class, especially with template class's constructor or destructor. I'm using CXXMethodDecl::getNameAsString to get the name of the function. For a non template class like struct C { C(); ~C(); //other stuff } The previous function gives me (as I expect) C and ~C. But if the class is template like the following: template <class TT,int N> struct C { C(); ~C(); } I get as result : C<TT, N> and ~C<TT, N>, which is not what I was expecting. For me, the name of a function should not be independent of the class being template. Classic functions behave the way I expect (same name in both cases). Am I missing something ? Is this the normal behavior or a bug ? Thank you ! David. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140217/69dd007c/attachment.html>
Kyle Sluder
2014-Feb-18 19:10 UTC
[LLVMdev] CXXMethodDecl::getNameAsString for template-class' constructor or destructor
On Feb 17, 2014, at 12:43 AM, David Come <davidbrcz at gmail.com> wrote:> > Hello ! > > I'm writing a small software to translate header into C++ files. It works fine for non-template class but I'm having n issue with template class, especially with template class's constructor or destructor. > > I'm using CXXMethodDecl::getNameAsString to get the name of the function. For a non template class like > > struct C > { > C(); > ~C(); > //other stuff > } > The previous function gives me (as I expect) C and ~C. > > But if the class is template like the following: > > template <class TT,int N> > struct C > { > C(); > ~C(); > } > I get as result : C<TT, N> and ~C<TT, N>, which is not what I was expecting. > > For me, the name of a function should not be independent of the class being template. Classic functions behave the way I expect (same name in both cases). > > > > Am I missing something ? Is this the normal behavior or a bug ? >I'm new to this myself, but: 1. This sounds like a question better-suited for cfe-dev, not llvmdev. 2. NamedDecl::getNameAsString() is deprecated; use getName() instead. 3. NamedDecl also as getDeclName(), which is documented to return “the actual, stored name of the declaration, which may be a special name.” --Kyle Sluder -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140218/a16fd6e0/attachment.html>