Skip to content

Commit ac73caf

Browse files
author
Erich Keane
committed
Ensure TreeTransform considers ParmVarDecls as transformed Decls
See PR47804: TreeTransform uses TransformedLocalDecls as a map of declarations that have been transformed already. When doing a "TransformDecl", which happens in the cases of updating a DeclRefExpr's target, the default implementation simply returns the already transformed declaration. However, this was not including ParmVarDecls. SO, any use of TreeTransform that didn't re-implement TransformDecl would NOT properly update the target of a DeclRefExpr, resulting in odd behavior. In the case of Typo-recovery, the result was that a lambda that used its own parameter would cause an error, since it thought that the ParmVarDecl referenced was a different lambda. Additionally, this caused a problem in the AST (a declrefexpr into another scope) such that a future instantiation would cause an assertion. This patch ensures that the ParmVarDecl transforming process records into TransformedLocalDecls so that the DeclRefExpr is ALSO updated.
1 parent 46d3e42 commit ac73caf

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5479,6 +5479,7 @@ ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
54795479
/* DefArg */ nullptr);
54805480
newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
54815481
OldParm->getFunctionScopeIndex() + indexAdjustment);
5482+
transformedLocalDecl(OldParm, {newParm});
54825483
return newParm;
54835484
}
54845485

clang/test/SemaCXX/pr47804.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s -verify
2+
3+
template <class InputIt, class Pred>
4+
bool all_of(InputIt first, Pred p);
5+
6+
template <typename T> void load_test() {
7+
// Ensure that this doesn't crash during CorrectDelayedTyposInExpr,
8+
// or any other use of TreeTransform that doesn't implement TransformDecl
9+
// separately. Also, this should only error on 'output', not that 'x' is not
10+
// captured.
11+
// expected-error@+1 {{use of undeclared identifier 'output'}}
12+
all_of(output, [](T x) { return x; });
13+
}
14+
15+
int main() {
16+
load_test<int>();
17+
return 0;
18+
}

0 commit comments

Comments
 (0)