[PATCH] D76038: PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in initializers

2022-01-04 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D76038#3219500 , @zahiraam wrote:

> This change is generating this crash discussed here: 
> https://bugs.llvm.org/show_bug.cgi?id=49834

Now migrated to https://github.com/llvm/llvm-project/issues/49178.

> @aaronpuchert do you have any fix for it?

No, everything I know is in that bug report. I was hoping @rsmith would reply 
with an idea, but it's quite complicated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76038

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76038: PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in initializers

2022-01-04 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

This change is generating this crash discussed here: 
https://bugs.llvm.org/show_bug.cgi?id=49834 
@aaronpuchert do you have any fix for it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76038

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76038: PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in initializers

2020-04-22 Thread Aaron Puchert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf43859a099fa: PR45000: Let Sema::SubstParmVarDecl handle 
default args of lambdas in… (authored by aaronpuchert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76038

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/AST/DeclBase.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/vartemplate-lambda.cpp
  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,16 @@
   }
   void g() { f(); }
 }
+
+namespace PR45000 {
+  template 
+  void f(int x = [](T x = nullptr) -> int { return x; }());
+  // expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'}}
+  // expected-note@-2 {{passing argument to parameter 'x' here}}
+  // expected-error@-3 {{no matching function for call}}
+  // expected-note@-4 {{candidate function not viable: requires single argument 'x', but no arguments were provided}}
+  // expected-note@-5 {{conversion candidate of type 'auto (*)(int) -> int'}}
+
+  void g() { f(); }
+  // expected-note@-1 {{in instantiation of default function argument expression for 'f' required here}}
+}
Index: clang/test/SemaCXX/vartemplate-lambda.cpp
===
--- clang/test/SemaCXX/vartemplate-lambda.cpp
+++ clang/test/SemaCXX/vartemplate-lambda.cpp
@@ -4,7 +4,12 @@
 template  void foo0() { fn0(); }
 
 template auto fn1 = [](auto a) { return a + T(1); };
-template auto v1 = [](int a = T(1)) { return a; }();
+template auto v1 = [](int a = T()) { return a; }();
+// expected-error@-1{{cannot initialize a parameter of type 'int' with an rvalue of type 'int *'}}
+// expected-error@-2{{no matching function for call}}
+// expected-note@-3{{passing argument to parameter 'a' here}}
+// expected-note@-4{{candidate function not viable}}
+// expected-note@-5{{conversion candidate of type 'int (*)(int)'}}
 
 struct S {
   template
@@ -16,6 +21,7 @@
   X a = 0x61;
   fn1(a);
   (void)v1;
+  (void)v1; // expected-note{{in instantiation of variable template specialization 'v1' requested here}}
   (void)S::t; // expected-note{{in instantiation of static data member 'S::t' requested here}}
   return 0;
 }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -12219,19 +12219,6 @@
 
   LSI->CallOperator = NewCallOperator;
 
-  for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
-   I != NumParams; ++I) {
-auto *P = NewCallOperator->getParamDecl(I);
-if (P->hasUninstantiatedDefaultArg()) {
-  EnterExpressionEvaluationContext Eval(
-  getSema(),
-  Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
-  ExprResult R = getDerived().TransformExpr(
-  E->getCallOperator()->getParamDecl(I)->getDefaultArg());
-  P->setDefaultArg(R.get());
-}
-  }
-
   getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
   getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4363,7 +4363,7 @@
 EPI.ExceptionSpec.Type != EST_None &&
 EPI.ExceptionSpec.Type != EST_DynamicNone &&
 EPI.ExceptionSpec.Type != EST_BasicNoexcept &&
-!Tmpl->isLexicallyWithinFunctionOrMethod()) {
+!Tmpl->isInLocalScope()) {
   FunctionDecl *ExceptionSpecTemplate = Tmpl;
   if (EPI.ExceptionSpec.Type == EST_Uninstantiated)
 ExceptionSpecTemplate = EPI.ExceptionSpec.SourceTemplate;
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2380,7 +2380,7 @@
 UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
   } else if (Expr *Arg = OldParm->getDefaultArg()) {
 FunctionDecl *OwningFunc = cast(OldParm->getDeclContext());
-if (OwningFunc->isLexicallyWithinFunctionOrMethod()) {
+if (OwningFunc->isInLocalScope()) {
   // Instantiate default arguments for methods of local classes (DR1484)
   // and non-defining declarations.
   Sema::ContextRAII SavedContext(*this, OwningFunc);
Index: clang/lib/AST/DeclBase.cpp

[PATCH] D76038: PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in initializers

2020-04-22 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

The test I have passes after applying this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76038



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76038: PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in initializers

2020-04-21 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

The responses to the various testcases you posted look OK to me. The language 
rules aren't clear, and we can revisit this if they get clarified in a 
different direction, but treating lambdas in variable templates the same as 
function definitions seems reasonable for now.

In D76038#1991426 , @aaronpuchert 
wrote:

> Adding @ahatanak and @sepavloff since I'm effectively reverting D23096 
>  now.


This looks reasonable to me, but maybe ping @ahatanak (on email / IRC / 
wherever) to make sure this isn't breaking something we don't have a test for.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76038



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76038: PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in initializers

2020-04-19 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added subscribers: ahatanak, sepavloff.
aaronpuchert added a comment.

Adding @ahatanak and @sepavloff since I'm effectively reverting D23096 
 now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76038



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76038: PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in initializers

2020-04-19 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert marked 2 inline comments as done.
aaronpuchert added a comment.

This seems to be in line with our current behavior, so I hope it's right:

  struct S { S(int); };
  
  template
  auto l = [](T x = T()) { return x; };
  
  template
  struct Fun {
  T operator()(T x = T()) const { return x; }
  };
  
  void f() {
  l();   // Ok.
  l(S(0)); // Error at "T()": no matching constructor for initialization 
of 'S'
  Fun f;
  f(S(0));// Ok.
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76038



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76038: PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in initializers

2020-04-19 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 258628.
aaronpuchert edited the summary of this revision.
aaronpuchert added a comment.

Slightly adapt test results: there is an additional error now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76038

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/AST/DeclBase.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/vartemplate-lambda.cpp
  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,16 @@
   }
   void g() { f(); }
 }
+
+namespace PR45000 {
+  template 
+  void f(int x = [](T x = nullptr) -> int { return x; }());
+  // expected-error@-1 {{cannot initialize a parameter of type 'int' with an rvalue of type 'nullptr_t'}}
+  // expected-note@-2 {{passing argument to parameter 'x' here}}
+  // expected-error@-3 {{no matching function for call}}
+  // expected-note@-4 {{candidate function not viable: requires single argument 'x', but no arguments were provided}}
+  // expected-note@-5 {{conversion candidate of type 'auto (*)(int) -> int'}}
+
+  void g() { f(); }
+  // expected-note@-1 {{in instantiation of default function argument expression for 'f' required here}}
+}
Index: clang/test/SemaCXX/vartemplate-lambda.cpp
===
--- clang/test/SemaCXX/vartemplate-lambda.cpp
+++ clang/test/SemaCXX/vartemplate-lambda.cpp
@@ -4,7 +4,12 @@
 template  void foo0() { fn0(); }
 
 template auto fn1 = [](auto a) { return a + T(1); };
-template auto v1 = [](int a = T(1)) { return a; }();
+template auto v1 = [](int a = T()) { return a; }();
+// expected-error@-1{{cannot initialize a parameter of type 'int' with an rvalue of type 'int *'}}
+// expected-error@-2{{no matching function for call}}
+// expected-note@-3{{passing argument to parameter 'a' here}}
+// expected-note@-4{{candidate function not viable}}
+// expected-note@-5{{conversion candidate of type 'int (*)(int)'}}
 
 struct S {
   template
@@ -16,6 +21,7 @@
   X a = 0x61;
   fn1(a);
   (void)v1;
+  (void)v1; // expected-note{{in instantiation of variable template specialization 'v1' requested here}}
   (void)S::t; // expected-note{{in instantiation of static data member 'S::t' requested here}}
   return 0;
 }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -12159,19 +12159,6 @@
 
   LSI->CallOperator = NewCallOperator;
 
-  for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
-   I != NumParams; ++I) {
-auto *P = NewCallOperator->getParamDecl(I);
-if (P->hasUninstantiatedDefaultArg()) {
-  EnterExpressionEvaluationContext Eval(
-  getSema(),
-  Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
-  ExprResult R = getDerived().TransformExpr(
-  E->getCallOperator()->getParamDecl(I)->getDefaultArg());
-  P->setDefaultArg(R.get());
-}
-  }
-
   getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
   getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4359,7 +4359,7 @@
 EPI.ExceptionSpec.Type != EST_None &&
 EPI.ExceptionSpec.Type != EST_DynamicNone &&
 EPI.ExceptionSpec.Type != EST_BasicNoexcept &&
-!Tmpl->isLexicallyWithinFunctionOrMethod()) {
+!Tmpl->isInLocalScope()) {
   FunctionDecl *ExceptionSpecTemplate = Tmpl;
   if (EPI.ExceptionSpec.Type == EST_Uninstantiated)
 ExceptionSpecTemplate = EPI.ExceptionSpec.SourceTemplate;
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2380,7 +2380,7 @@
 UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
   } else if (Expr *Arg = OldParm->getDefaultArg()) {
 FunctionDecl *OwningFunc = cast(OldParm->getDeclContext());
-if (OwningFunc->isLexicallyWithinFunctionOrMethod()) {
+if (OwningFunc->isInLocalScope()) {
   // Instantiate default arguments for methods of local classes (DR1484)
   // and non-defining declarations.
   Sema::ContextRAII SavedContext(*this, OwningFunc);
Index: clang/lib/AST/DeclBase.cpp

[PATCH] D76038: PR45000: Let Sema::SubstParmVarDecl handle default args of lambdas in initializers

2020-04-19 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 258627.
aaronpuchert added a comment.

Remove loop in TreeTransform::TransformLambdaExpr and make sure 
Sema::SubstParmVarDecl handles the situation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76038

Files:
  clang/include/clang/AST/DeclBase.h
  clang/lib/AST/DeclBase.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/vartemplate-lambda.cpp
  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(); }
 }
+
+namespace PR45000 {
+  template 
+  void f(int x = [](T x = nullptr) -> int { return x; }());
+  // expected-error@-1 {{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()'}}
+  // expected-note@-3 {{passing argument to parameter 'x' here}}
+
+  void g() { f(); }
+  // expected-note@-1 {{in instantiation of default function argument expression for 'f'}}
+}
Index: clang/test/SemaCXX/vartemplate-lambda.cpp
===
--- clang/test/SemaCXX/vartemplate-lambda.cpp
+++ clang/test/SemaCXX/vartemplate-lambda.cpp
@@ -4,7 +4,12 @@
 template  void foo0() { fn0(); }
 
 template auto fn1 = [](auto a) { return a + T(1); };
-template auto v1 = [](int a = T(1)) { return a; }();
+template auto v1 = [](int a = T()) { return a; }();
+// expected-error@-1{{cannot initialize a parameter of type 'int' with an rvalue of type 'int *'}}
+// expected-error@-2{{no matching function for call}}
+// expected-note@-3{{passing argument to parameter 'a' here}}
+// expected-note@-4{{candidate function not viable}}
+// expected-note@-5{{conversion candidate of type 'int (*)(int)'}}
 
 struct S {
   template
@@ -16,6 +21,7 @@
   X a = 0x61;
   fn1(a);
   (void)v1;
+  (void)v1; // expected-note{{in instantiation of variable template specialization 'v1' requested here}}
   (void)S::t; // expected-note{{in instantiation of static data member 'S::t' requested here}}
   return 0;
 }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -12159,19 +12159,6 @@
 
   LSI->CallOperator = NewCallOperator;
 
-  for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
-   I != NumParams; ++I) {
-auto *P = NewCallOperator->getParamDecl(I);
-if (P->hasUninstantiatedDefaultArg()) {
-  EnterExpressionEvaluationContext Eval(
-  getSema(),
-  Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
-  ExprResult R = getDerived().TransformExpr(
-  E->getCallOperator()->getParamDecl(I)->getDefaultArg());
-  P->setDefaultArg(R.get());
-}
-  }
-
   getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
   getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4359,7 +4359,7 @@
 EPI.ExceptionSpec.Type != EST_None &&
 EPI.ExceptionSpec.Type != EST_DynamicNone &&
 EPI.ExceptionSpec.Type != EST_BasicNoexcept &&
-!Tmpl->isLexicallyWithinFunctionOrMethod()) {
+!Tmpl->isInLocalScope()) {
   FunctionDecl *ExceptionSpecTemplate = Tmpl;
   if (EPI.ExceptionSpec.Type == EST_Uninstantiated)
 ExceptionSpecTemplate = EPI.ExceptionSpec.SourceTemplate;
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2380,7 +2380,7 @@
 UnparsedDefaultArgInstantiations[OldParm].push_back(NewParm);
   } else if (Expr *Arg = OldParm->getDefaultArg()) {
 FunctionDecl *OwningFunc = cast(OldParm->getDeclContext());
-if (OwningFunc->isLexicallyWithinFunctionOrMethod()) {
+if (OwningFunc->isInLocalScope()) {
   // Instantiate default arguments for methods of local classes (DR1484)
   // and non-defining declarations.
   Sema::ContextRAII SavedContext(*this, OwningFunc);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -332,13 +332,16 @@
   }
 }
 
-bool Decl::isLexicallyWithinFunctionOrMethod() const {