ahatanak updated this revision to Diff 81171.
ahatanak added a comment.
Rebase and ping.
https://reviews.llvm.org/D23096
Files:
lib/Sema/SemaTemplate.cpp
lib/Sema/SemaTemplateInstantiate.cpp
lib/Sema/TreeTransform.h
test/SemaCXX/vartemplate-lambda.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,35 @@
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -disable-llvm-optzns -verify %s
+// expected-no-diagnostics
+
+namespace PR28795 {
+ template<typename T>
+ void func() {
+ enum class foo { a, b };
+ auto bar = [](foo f = foo::a) { return f; };
+ bar();
+ }
+
+ void foo() {
+ func<int>();
+ }
+}
+
+// Template struct case:
+template <class T> struct class2 {
+ void bar() {
+ enum class foo { a, b };
+ [](foo f = foo::a) { return f; }();
+ }
+};
+
+template struct class2<int>;
+
+template<typename T>
+void f1() {
+ enum class foo { a, b };
+ struct S {
+ int g1(foo n = foo::a);
+ };
+}
+
+template void f1<int>();
Index: test/SemaCXX/vartemplate-lambda.cpp
===================================================================
--- test/SemaCXX/vartemplate-lambda.cpp
+++ test/SemaCXX/vartemplate-lambda.cpp
@@ -1,18 +1,36 @@
// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
-// expected-no-diagnostics
template <class> auto fn0 = [] {};
template <typename> void foo0() { fn0<char>(); }
template<typename T> auto fn1 = [](auto a) { return a + T(1); };
+template<typename T> auto v1 = [](int a = T(1)) { return a; }();
+
+struct S {
+ template<class T>
+ static constexpr T t = [](int f = T(7)){return f;}(); // expected-error{{constexpr variable 't<int>' must be initialized by a constant expression}} expected-error{{a lambda expression may not appear inside of a constant expression}} expected-note{{cannot be used in a constant expression}}
+};
template <typename X>
int foo2() {
X a = 0x61;
fn1<char>(a);
+ (void)v1<int>;
+ (void)S::t<int>; // expected-note{{in instantiation of static data member 'S::t<int>' requested here}}
return 0;
}
+template<class C>
+int foo3() {
+ C::m1(); // expected-error{{type 'long long' cannot be used prior to '::' because it has no members}}
+ return 1;
+}
+
+template<class C>
+auto v2 = [](int a = foo3<C>()){}; // expected-note{{in instantiation of function template specialization 'foo3<long long>' requested here}}
+
int main() {
+ v2<long long>(); // This line causes foo3<long long> to be instantiated.
+ v2<long long>(2); // This line does not.
foo2<int>();
}
Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -10356,6 +10356,18 @@
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::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: lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -1687,7 +1687,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: lib/Sema/SemaTemplate.cpp
===================================================================
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -429,7 +429,12 @@
bool MightBeCxx11UnevalField =
getLangOpts().CPlusPlus11 && isUnevaluatedContext();
- if (!MightBeCxx11UnevalField && !isAddressOfOperand &&
+ // Check if the nested name specifier is an enum type.
+ bool IsEnum = false;
+ if (NestedNameSpecifier *NNS = SS.getScopeRep())
+ IsEnum = dyn_cast_or_null<EnumType>(NNS->getAsType());
+
+ if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum &&
isa<CXXMethodDecl>(DC) && cast<CXXMethodDecl>(DC)->isInstance()) {
QualType ThisType = cast<CXXMethodDecl>(DC)->getThisType(Context);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits