Add support for calls to dependent names within templates, e.g.,

  template<typename T> void f(T x) {
    g(x); // g is a dependent name, so don't even bother to look it up
    g(); // error: g is not a dependent name
  }

Note that when we see "g(", we build a CXXDependentNameExpr. However,
if none of the call arguments are type-dependent, we will force the
resolution of the name "g" and replace the CXXDependentNameExpr with
its result.

GCC actually produces a nice error message when you make this
mistake, and even offers to compile your code with -fpermissive. I'll
do the former next, but I don't plan to do the latter.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60618 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index 2d51719..b5d5b4c 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -112,6 +112,14 @@
 Stmt::child_iterator CXXDeleteExpr::child_begin() { return &Argument; }
 Stmt::child_iterator CXXDeleteExpr::child_end() { return &Argument+1; }
 
+// CXXDependentNameExpr
+Stmt::child_iterator CXXDependentNameExpr::child_begin() { 
+  return child_iterator(); 
+}
+Stmt::child_iterator CXXDependentNameExpr::child_end() {
+  return child_iterator();
+}
+
 OverloadedOperatorKind CXXOperatorCallExpr::getOperator() const {
   // All simple function calls (e.g. func()) are implicitly cast to pointer to
   // function. As a result, we try and obtain the DeclRefExpr from the 
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index 2e54777..94bca63 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -988,6 +988,10 @@
   PrintExpr(E->getArgument());
 }
 
+void StmtPrinter::VisitCXXDependentNameExpr(CXXDependentNameExpr *E) {
+  OS << E->getName()->getName();
+}
+
 // Obj-C 
 
 void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp
index 6ebaca1..9b6207b 100644
--- a/lib/AST/StmtSerialization.cpp
+++ b/lib/AST/StmtSerialization.cpp
@@ -239,6 +239,9 @@
 
     case CXXDeleteExprClass:
       return CXXDeleteExpr::CreateImpl(D, C);
+
+    case CXXDependentNameExprClass:
+      return CXXDependentNameExpr::CreateImpl(D, C);
   }
 }
 
@@ -1506,3 +1509,17 @@
   return new CXXDeleteExpr(Ty, GlobalDelete, ArrayForm, OperatorDelete,
                            cast<Expr>(Argument), Loc);
 }
+
+void CXXDependentNameExpr::EmitImpl(llvm::Serializer& S) const {
+  S.Emit(getType());
+  S.EmitPtr(Name);
+  S.Emit(Loc);
+}
+
+CXXDependentNameExpr *
+CXXDependentNameExpr::CreateImpl(llvm::Deserializer& D, ASTContext& C) {
+  QualType Ty = QualType::ReadVal(D);
+  IdentifierInfo *N = D.ReadPtr<IdentifierInfo>();
+  SourceLocation L = SourceLocation::ReadVal(D);
+  return new CXXDependentNameExpr(N, Ty, L);
+}