[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

Serge Preis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 25 02:39:40 PDT 2017


Serge_Preis added a comment.



In https://reviews.llvm.org/D32439#736503, @malcolm.parsons wrote:

> Is it possible to add a test for this change?
>  There are some source range checks in test/Misc/ast-dump-decl.cpp


Yes, I think testing is quite possible. I will take a look into test/Misc/ast-dump-decl.cpp and try to come up with something meaningful.

The code exposed this issue for me looked like this:

  template<typename EntityT>
  bool checkNameAtPos(const EntityT entity) {
       std::string name = GetName(entity);  /// EntityT-dependent way to discover name 
       SourceLoc start = GetStart(entity);    /// entity.getBeginLoc() by default with rare exceptions
  
      const char* buf = SourceMgr.getCharacterData(start, &err);
      assert(!err && "getCharacterData() failed");
  
      if (buf[0] != name[0]) {
          llvm::errs() << "Anchor text doesn't match the symbol:\n"
                          << "  Name = " << nameStr << "\n"
                          << "  @Anchor = " << bufStr << "\n"
          start.print(llvm::errs(), SourceMgr);
          llvm::errs() << '\n';
          return false;
      }
      return true;
  }

I wanted to be sure that there will be a name of an enity in the entity's location (at least prefix of entity's name). So tesing for something like this may be added for entities being TypeLoc, NestedNameSpecifier and CXXCtorInitializer.


https://reviews.llvm.org/D32439





More information about the cfe-commits mailing list