aaronpuchert updated this revision to Diff 257938.
aaronpuchert added a comment.

Add test case, loosely based on that in the bug report. By choosing a 
conversion that should error out we can detect the issue in a pure frontend 
test.

However, we would expect the error only once. Further investigation is needed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76038/new/

https://reviews.llvm.org/D76038

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaTemplate/instantiate-local-class.cpp


Index: clang/test/SemaTemplate/instantiate-local-class.cpp
===================================================================
--- clang/test/SemaTemplate/instantiate-local-class.cpp
+++ clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -486,3 +486,14 @@
   }
   void g() { f<int>(); }
 }
+
+namespace PR45000 {
+  template <typename T>
+  void f(int x = [](T x = nullptr) -> int { return x; }());
+  // expected-error@-1 2 {{cannot initialize a parameter of type 'int' with an 
rvalue of type 'nullptr_t'}}
+  // expected-note@-2 {{in instantiation of default function argument 
expression for 'operator()<int>'}}
+  // expected-note@-3 2 {{passing argument to parameter 'x' here}}
+
+  void g() { f<int>(); }
+  // expected-note@-1 2 {{in instantiation of default function argument 
expression for 'f<int>'}}
+}
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -12168,7 +12168,7 @@
           Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
       ExprResult R = getDerived().TransformExpr(
           E->getCallOperator()->getParamDecl(I)->getDefaultArg());
-      P->setDefaultArg(R.get());
+      getSema().SetParamDefaultArgument(P, R.get(), R.get()->getBeginLoc());
     }
   }
 


Index: clang/test/SemaTemplate/instantiate-local-class.cpp
===================================================================
--- clang/test/SemaTemplate/instantiate-local-class.cpp
+++ clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -486,3 +486,14 @@
   }
   void g() { f<int>(); }
 }
+
+namespace PR45000 {
+  template <typename T>
+  void f(int x = [](T x = nullptr) -> int { return x; }());
+  // expected-error@-1 2 {{cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'}}
+  // expected-note@-2 {{in instantiation of default function argument expression for 'operator()<int>'}}
+  // expected-note@-3 2 {{passing argument to parameter 'x' here}}
+
+  void g() { f<int>(); }
+  // expected-note@-1 2 {{in instantiation of default function argument expression for 'f<int>'}}
+}
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -12168,7 +12168,7 @@
           Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
       ExprResult R = getDerived().TransformExpr(
           E->getCallOperator()->getParamDecl(I)->getDefaultArg());
-      P->setDefaultArg(R.get());
+      getSema().SetParamDefaultArgument(P, R.get(), R.get()->getBeginLoc());
     }
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to