[clang] [Clang][Sema] Fix malformed AST for anonymous class access in template. (PR #90842)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Thu May 2 14:18:39 PDT 2024
================
@@ -2876,10 +2876,21 @@ class TreeTransform {
return ExprError();
Base = BaseResult.get();
+ // We want to use `BuildMemberReferenceExpr()` so we can use its logic
+ // that materializes `Base` into a temporary if it's a prvalue.
+ // To do so, we need to create a `LookupResult` for `Member`, even though
+ // it's an unnamed field (that we could never actually have looked up).
+ // This small hack seems preferable to duplicating the logic for
+ // materializing the temporary.
+ LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
+ R.addDecl(Member);
+ R.resolveKind();
+
CXXScopeSpec EmptySS;
- return getSema().BuildFieldReferenceExpr(
- Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
- DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
+ return getSema().BuildMemberReferenceExpr(
+ Base, Base->getType(), OpLoc, isArrow, EmptySS, TemplateKWLoc,
+ FirstQualifierInScope, R, ExplicitTemplateArgs,
+ /*S*/ nullptr);
----------------
shafik wrote:
```suggestion
/*S=*/nullptr);
```
We use [bugprone-argument-comment](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html) format for these.
https://github.com/llvm/llvm-project/pull/90842
More information about the cfe-commits
mailing list