Issue 71161
Summary [clang] Wrong SourceRange returned by getNameInfo() for template instantiations of CXXDestructorDecls
Labels bug, clang:frontend, regression
Assignees tahonermann
Reporter steakhal
    [D64087](https://reviews.llvm.org/D64087) appears to break some downstream code that relies on the expectation summarized in this unittest:

```C++
TEST(Regression, CXXDestructorDeclsShouldHaveWellFormedRanges) {
  std::unique_ptr<ASTUnit> AST = buildASTFromCode(R"cpp(
template <typename T> struct Resource {
 ~Resource();
};
template <typename T>
Resource<T>::~Resource() {}
 
void instantiate_template() {
  Resource<int> x;
}
)cpp",
 "foo.cpp");
  auto &SM = AST->getASTContext().getSourceManager();
 
  auto Matches = match(
 findAll(decl(hasDescendant(cxxDestructorDecl().bind("dtor")))),
 *AST->getASTContext().getTranslationUnitDecl(), AST->getASTContext());
 
  for (BoundNodes Match : Matches) {
    const auto *D = Match.getNodeAs<CXXDestructorDecl>("dtor");
    assert(D);
    auto Range = D->getNameInfo().getSourceRange();
    if (Range.getBegin() != Range.getEnd()) {
      ASSERT_TRUE(
 SM.isBeforeInTranslationUnit(Range.getBegin(), Range.getEnd()));
    }
 }
}
```

The test describes that for all `CXXDestructorDecl` the corresponding `getNameInfo()` should return a `SourceRange` where the begin location is before then the end location (if they were not the same of course).
This test passes before commit 256a0b298c68b89688b80350b034daf2f7785b67 `[clang] Correct source locations for instantiations of function templates.` (2023.09.12) but breaks after that.

IMO this expectation sounds right, and I believe it should hold.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to