Give L__FUNCTION__ the right type in templates. PR13206.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159171 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index b26e79b..b80aaa2 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1093,7 +1093,11 @@
   unsigned Length = PredefinedExpr::ComputeName(IT, currentDecl).length();
 
   llvm::APInt LengthI(32, Length + 1);
-  QualType ResTy = getSema().Context.CharTy.withConst();
+  QualType ResTy;
+  if (IT == PredefinedExpr::LFunction)
+    ResTy = getSema().Context.WCharTy.withConst();
+  else
+    ResTy = getSema().Context.CharTy.withConst();
   ResTy = getSema().Context.getConstantArrayType(ResTy, LengthI, 
                                                  ArrayType::Normal, 0);
   PredefinedExpr *PE =
diff --git a/test/Sema/ms_wide_predefined_expr.cpp b/test/Sema/ms_wide_predefined_expr.cpp
index 4df64dc..8e816e0 100644
--- a/test/Sema/ms_wide_predefined_expr.cpp
+++ b/test/Sema/ms_wide_predefined_expr.cpp
@@ -7,3 +7,19 @@
  const wchar_t (*ss)[12] = &STR2WSTR(__FUNCTION__);
  static int arr[sizeof(STR2WSTR(__FUNCTION__))==12*sizeof(wchar_t) ? 1 : -1];
 }
+
+namespace PR13206 {
+void foo(const wchar_t *);
+
+template<class T> class A {
+public:
+ void method() {
+  foo(L__FUNCTION__);
+ }
+};
+
+void bar() {
+ A<int> x;
+ x.method();
+}
+}