Make the parser handle ::new and ::delete correctly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60421 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index df46612..50b3a7a 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -638,8 +638,13 @@
     Res = ParseCXXIdExpression();
     return ParsePostfixExpressionSuffix(Res);
 
+  case tok::coloncolon: // [C++] new-expression or [C++] delete-expression
+    if (NextToken().is(tok::kw_new))
+      return ParseCXXNewExpression();
+    else
+      return ParseCXXDeleteExpression();
+
   case tok::kw_new: // [C++] new-expression
-    // FIXME: ParseCXXIdExpression currently steals :: tokens.
     return ParseCXXNewExpression();
 
   case tok::kw_delete: // [C++] delete-expression
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index d995b88..5d790fa 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -38,6 +38,12 @@
       (Tok.isNot(tok::identifier) || NextToken().isNot(tok::coloncolon)))
     return false;
 
+  // Don't parse ::new and ::delete as scope specifiers. It would only make
+  // things a lot more complicated.
+  if (Tok.is(tok::coloncolon) && (NextToken().is(tok::kw_new) ||
+                                  NextToken().is(tok::kw_delete)))
+    return false;
+
   if (Tok.is(tok::annot_cxxscope)) {
     SS.setScopeRep(Tok.getAnnotationValue());
     SS.setRange(Tok.getAnnotationRange());
diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp
index 0a1a3ae..d9b4713 100644
--- a/test/SemaCXX/new-delete.cpp
+++ b/test/SemaCXX/new-delete.cpp
@@ -21,6 +21,7 @@
   ps = new (S[3])(1, 2, 3.4);
   typedef int ia4[4];
   ia4 *pai = new (int[3][4]);
+  pi = ::new int;
 }
 
 void bad_news(int *ip)
@@ -41,6 +42,7 @@
   // Undefined, but clang should reject it directly.
   (void)new int[-1]; // expected-error {{array size is negative}}
   (void)new int[*(S*)0]; // expected-error {{array size expression must have integral or enumerated type, not 'struct S'}}
+  (void)::S::new int; // expected-error {{expected unqualified-id}}
   // Some lacking cases due to lack of sema support.
 }
 
@@ -49,6 +51,7 @@
   delete (int*)0;
   delete [](int*)0;
   delete (S*)0;
+  ::delete (int*)0;
 }
 
 void bad_deletes()
@@ -58,4 +61,5 @@
                       // expected-note {{to match this '['}}
   delete (void*)0; // expected-error {{cannot delete expression}}
   delete (T*)0; // expected-warning {{deleting pointer to incomplete type}}
+  ::S::delete (int*)0; // expected-error {{expected unqualified-id}}
 }