Diagnose attempts to use C++ default arguments outside of a function declaration

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50799 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 2624f50..9e9509a 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -785,6 +785,10 @@
   assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
 
   if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
+    // Check that there are no default arguments (C++ only).
+    if (getLangOptions().CPlusPlus)
+      CheckExtraCXXDefaultArguments(D);
+
     TypedefDecl *NewTD = ParseTypedefDecl(S, D, R, LastDeclarator);
     if (!NewTD) return 0;
 
@@ -889,6 +893,10 @@
     if (getLangOptions().CPlusPlus)
       CheckCXXDefaultArguments(NewFD);
   } else {
+    // Check that there are no default arguments (C++ only).
+    if (getLangOptions().CPlusPlus)
+      CheckExtraCXXDefaultArguments(D);
+
     if (R.getTypePtr()->isObjCInterfaceType()) {
       Diag(D.getIdentifierLoc(), diag::err_statically_allocated_object,
            D.getIdentifier()->getName());
@@ -1108,7 +1116,11 @@
     DS.ClearStorageClassSpecs();
   }
   
-  
+  // Check that there are no default arguments inside the type of this
+  // parameter (C++ only).
+  if (getLangOptions().CPlusPlus)
+    CheckExtraCXXDefaultArguments(D);
+ 
   // In this context, we *do not* check D.getInvalidType(). If the declarator
   // type was invalid, GetTypeForDeclarator() still returns a "valid" type,
   // though it will not reflect the user specified type.