Make ParmVarDecl::getDefaultArg() more robust, it now asserts that the argument is not unparsed. Add a new hasDefaultArg() and use it in places where getDefaultArg() was called when the argument was unparsed.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72984 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index e134aed..7440e7b 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -515,10 +515,22 @@
     objcDeclQualifier = QTVal;
   }
     
-  const Expr *getDefaultArg() const { return DefaultArg; }
-  Expr *getDefaultArg() { return DefaultArg; }
+  const Expr *getDefaultArg() const { 
+    assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!");
+    return DefaultArg; 
+  }
+  Expr *getDefaultArg() { 
+    assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!");
+    return DefaultArg; 
+  }
   void setDefaultArg(Expr *defarg) { DefaultArg = defarg; }
 
+  /// hasDefaultArg - Determines whether this parameter has a default argument,
+  /// either parsed or not.
+  bool hasDefaultArg() const {
+    return DefaultArg != 0;
+  }
+  
   /// hasUnparsedDefaultArg - Determines whether this parameter has a
   /// default argument that has not yet been parsed. This will occur
   /// during the processing of a C++ class whose member functions have
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index cb3ec1f..dfec106 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -489,7 +489,7 @@
 unsigned FunctionDecl::getMinRequiredArguments() const {
   unsigned NumRequiredArgs = getNumParams();
   while (NumRequiredArgs > 0
-         && getParamDecl(NumRequiredArgs-1)->getDefaultArg())
+         && getParamDecl(NumRequiredArgs-1)->hasDefaultArg())
     --NumRequiredArgs;
 
   return NumRequiredArgs;
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 19f8958..94daf48 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -326,7 +326,7 @@
   //   const volatile X&, and either there are no other parameters
   //   or else all other parameters have default arguments (8.3.6).
   if ((getNumParams() < 1) ||
-      (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() == 0))
+      (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()))
     return false;
 
   const ParmVarDecl *Param = getParamDecl(0);
@@ -363,7 +363,7 @@
   return (getNumParams() == 0 && 
           getType()->getAsFunctionProtoType()->isVariadic()) ||
          (getNumParams() == 1) ||
-         (getNumParams() > 1 && getParamDecl(1)->getDefaultArg() != 0);
+         (getNumParams() > 1 && getParamDecl(1)->hasDefaultArg());
 }
 
 CXXDestructorDecl *
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index f13179f..b59ac87 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -1357,7 +1357,7 @@
   if (!Constructor->isInvalidDecl() &&
       ((Constructor->getNumParams() == 1) || 
        (Constructor->getNumParams() > 1 && 
-        Constructor->getParamDecl(1)->getDefaultArg() != 0))) {
+        Constructor->getParamDecl(1)->hasDefaultArg()))) {
     QualType ParamType = Constructor->getParamDecl(0)->getType();
     QualType ClassTy = Context.getTagDeclType(ClassDecl);
     if (Context.getCanonicalType(ParamType).getUnqualifiedType() == ClassTy) {