<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71161>71161</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Wrong SourceRange returned by getNameInfo() for template instantiations of CXXDestructorDecls
</td>
</tr>
<tr>
<th>Labels</th>
<td>
bug,
clang:frontend,
regression
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
tahonermann
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
steakhal
</td>
</tr>
</table>
<pre>
[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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8Vk2Po7oS_TXOpjQRMYHAIgs6dPR60fOkTkYzu5GxC_AbsPNs0x93cX_7lQ0k6WTmSiggV6Wqzjnlspm1slGIW5I8EEoda7VC0z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