[cfe-commits] r42412 - in /cfe/trunk: AST/Decl.cpp Parse/ParseObjc.cpp Parse/Parser.cpp Sema/Sema.h Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Decl.h include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Action.h include/clang/Parse/Parser.h test/Sema/method-undefined-warn-1.m

Chris Lattner clattner at apple.com
Thu Oct 4 15:26:43 PDT 2007

>>> As far as getName() is concerned, I am concerned about lifetime.  
>>> By passing a buffer in, it is clear the client owns the buffer.  
>>> If getName() returns a string buffer, the ownership is unclear. I  
>>> don't have a strong opinion on this...I just want to point out my  
>>> (minor) issue/concern. Clearly, not having to pass in a buffer is  
>>> more convenient...
>> Since we have getName() for Identifiers, it makes sense to have  
>> one for selectors with a buyer-beware clause added to it :).
> Seems confusing to me. When using IdentifierInfo::getName(), you  
> *cannot* free the result (or bad things will happen:-). However,  
> when using Selector::getName() you *must* free the result.

Just return the std::string by-value.  The std::string will own the  
memory returned.

You can even make use a smallstring internally to build the buffer,  
then use:
   return std::string(Buf.begin(), Buf.end());

when it is returned (which copies the memory out of the SmallString  
onto the heap).  Note that the null terminator should be removed from  
the string for std::string.


More information about the cfe-commits mailing list