ahatanak created this revision.
ahatanak added reviewers: rsmith, sepavloff.
ahatanak added a subscriber: cfe-commits.

This fixes PR28795.

https://llvm.org/bugs/show_bug.cgi?id=28795

Sema wasn't replacing DependentScopeDeclRefExpr with DeclRefExpr during 
template instantiation of the default argument of the lambda function because 
it failed to find the instantiated enum "foo" in LocalInstantiationScope. This 
patch fixes the bug by allowing it to search the outer scope (function func).

https://reviews.llvm.org/D23096

Files:
  lib/Sema/SemaTemplateInstantiate.cpp
  test/SemaTemplate/default-expr-arguments-3.cpp

Index: test/SemaTemplate/default-expr-arguments-3.cpp
===================================================================
--- /dev/null
+++ test/SemaTemplate/default-expr-arguments-3.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++14 -ast-dump %s 2>&1 | FileCheck %s
+
+namespace PR28795 {
+  // CHECK: FunctionDecl{{.*}}func 'void (void)'
+  // CHECK:  LambdaExpr
+  // CHECK:   CXXMethodDecl{{.*}}operator() 'enum foo (enum foo) const' inline
+  // CHECK:    ParmVarDecl{{.*}}f 'enum foo' cinit
+  // CHECK:     DeclRefExpr{{.*}}'enum foo' EnumConstant{{.*}}'a' 'enum foo'
+
+  template<typename T>
+  void func() {
+    enum class foo { a, b };
+    auto bar = [](foo f = foo::a) { return f; };
+    bar();
+  }
+
+  void foo() {
+    func<int>();
+  }
+}
Index: lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -1670,7 +1670,7 @@
       // Instantiate default arguments for methods of local classes (DR1484)
       // and non-defining declarations.
       Sema::ContextRAII SavedContext(*this, OwningFunc);
-      LocalInstantiationScope Local(*this);
+      LocalInstantiationScope Local(*this, true);
       ExprResult NewArg = SubstExpr(Arg, TemplateArgs);
       if (NewArg.isUsable()) {
         // It would be nice if we still had this.


Index: test/SemaTemplate/default-expr-arguments-3.cpp
===================================================================
--- /dev/null
+++ test/SemaTemplate/default-expr-arguments-3.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++14 -ast-dump %s 2>&1 | FileCheck %s
+
+namespace PR28795 {
+  // CHECK: FunctionDecl{{.*}}func 'void (void)'
+  // CHECK:  LambdaExpr
+  // CHECK:   CXXMethodDecl{{.*}}operator() 'enum foo (enum foo) const' inline
+  // CHECK:    ParmVarDecl{{.*}}f 'enum foo' cinit
+  // CHECK:     DeclRefExpr{{.*}}'enum foo' EnumConstant{{.*}}'a' 'enum foo'
+
+  template<typename T>
+  void func() {
+    enum class foo { a, b };
+    auto bar = [](foo f = foo::a) { return f; };
+    bar();
+  }
+
+  void foo() {
+    func<int>();
+  }
+}
Index: lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -1670,7 +1670,7 @@
       // Instantiate default arguments for methods of local classes (DR1484)
       // and non-defining declarations.
       Sema::ContextRAII SavedContext(*this, OwningFunc);
-      LocalInstantiationScope Local(*this);
+      LocalInstantiationScope Local(*this, true);
       ExprResult NewArg = SubstExpr(Arg, TemplateArgs);
       if (NewArg.isUsable()) {
         // It would be nice if we still had this.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to