[clang] [Clang] Workaround dependent source location issues (PR #106925)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 10:30:43 PDT 2024


================
@@ -5443,11 +5443,24 @@ struct EnsureImmediateInvocationInDefaultArgs
 
   // Rewrite to source location to refer to the context in which they are used.
   ExprResult TransformSourceLocExpr(SourceLocExpr *E) {
-    if (E->getParentContext() == SemaRef.CurContext)
+    DeclContext *DC = E->getParentContext();
+    if (DC == SemaRef.CurContext)
       return E;
-    return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
-                                             E->getBeginLoc(), E->getEndLoc(),
-                                             SemaRef.CurContext);
+
+    // FIXME: During instantiation, because the rebuild of defaults arguments
+    // is not always done in the context of the template instantiator,
+    // we run the risk of producing a dependent source location
+    // that would never be rebuilt.
+    // This usually happen during overloadĀ resolution, or in contexts
+    // where the value of the source location does not matter.
+    // However, we should find a better way to deal with source location
+    // of function template.
----------------
AaronBallman wrote:

```suggestion
    // of function templates.
```

https://github.com/llvm/llvm-project/pull/106925


More information about the cfe-commits mailing list