[cfe-dev] CXXRecordDecl Name

Reid Kleckner rnk at google.com
Mon Jun 30 15:35:50 PDT 2014


Try getDeclName(), getNameAsString(), or others.  getName() only works if
the name is a simple identifier:

  /// getName - Get the name of identifier for this declaration as a
StringRef.
  /// This requires that the declaration have a name and that it be a simple
  /// identifier.
  StringRef getName() const {
    assert(Name.isIdentifier() && "Name is not a simple identifier");
    return getIdentifier() ? getIdentifier()->getName() : "";
  }



On Mon, Jun 30, 2014 at 3:21 PM, Daniel Dilts <diltsman at gmail.com> wrote:

> I am attempting to get the name of a CXXRecordDecl that I have identified
> with an AST matcher.  I am using Class->getName().str() to get the class
> name.
>
> namespace N {
> class SomeNonInterface {
>   virtual void func1() = 0;
>   virtual void func2() {}
> };
> }
>
> It works great for the above code.  Gives me "SomeNonInterface" as the
> name.
>
> class N::BaseClass1 {
> public:
>   BaseClass1(int i);
>   BaseClass1(const BaseClass1 &right);
>   virtual ~BaseClass1();
>   BaseClass1 &operator=(const BaseClass1 &right);
> };
>
> For the above code it gives me "" as the name.
>
> How would I get the class name so that it works in all cases, even if the
> name in the declaration/definition is namespace qualified?  Or...did I hit
> a case that isn't legal?
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140630/4ef55076/attachment.html>


More information about the cfe-dev mailing list