decltype(e) is type-dependent if e is instantiation-dependent. Scary but true.
Don't consider decltype(e) for an instantiation-dependent, but not
type-dependent, e to be non-type-dependent but canonical(!).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148210 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 99468b8..7fd83b5 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -1739,7 +1739,10 @@
 }
 
 DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can)
-  : Type(Decltype, can, E->isTypeDependent(), 
+  // C++11 [temp.type]p2: "If an expression e involves a template parameter,
+  // decltype(e) denotes a unique dependent type." Hence a decltype type is
+  // type-dependent even if its expression is only instantiation-dependent.
+  : Type(Decltype, can, E->isInstantiationDependent(),
          E->isInstantiationDependent(),
          E->getType()->isVariablyModifiedType(), 
          E->containsUnexpandedParameterPack()), 
diff --git a/test/SemaCXX/decltype.cpp b/test/SemaCXX/decltype.cpp
index 78fb8ef..a1200e0 100644
--- a/test/SemaCXX/decltype.cpp
+++ b/test/SemaCXX/decltype.cpp
@@ -20,4 +20,11 @@
   class A{
       A(decltype(nullptr) param);
   };
-}
\ No newline at end of file
+}
+
+template<typename T> struct S {};
+template<typename T> auto f(T t) -> decltype(S<int>(t)) {
+  using U = decltype(S<int>(t));
+  using U = S<int>;
+  return S<int>(t);
+}