[cfe-commits] r60421 - in /cfe/trunk: lib/Parse/ParseExpr.cpp lib/Parse/ParseExprCXX.cpp test/SemaCXX/new-delete.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Tue Dec 2 08:35:44 PST 2008
Author: cornedbee
Date: Tue Dec 2 10:35:44 2008
New Revision: 60421
URL: http://llvm.org/viewvc/llvm-project?rev=60421&view=rev
Log:
Make the parser handle ::new and ::delete correctly.
Modified:
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/test/SemaCXX/new-delete.cpp
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=60421&r1=60420&r2=60421&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Dec 2 10:35:44 2008
@@ -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
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=60421&r1=60420&r2=60421&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Tue Dec 2 10:35:44 2008
@@ -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());
Modified: cfe/trunk/test/SemaCXX/new-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/new-delete.cpp?rev=60421&r1=60420&r2=60421&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/new-delete.cpp (original)
+++ cfe/trunk/test/SemaCXX/new-delete.cpp Tue Dec 2 10:35:44 2008
@@ -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}}
}
More information about the cfe-commits
mailing list