[PATCH] D23096: [Sema] Pass CombineWithOuterScope = true to constructor of LocalInstantiationScope
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 2 16:39:39 PDT 2016
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23096.66591.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160802/61d951d9/attachment.bin>
More information about the cfe-commits
mailing list