[cfe-commits] r91040 - in /cfe/trunk: lib/Parse/ParseExpr.cpp lib/Parse/RAIIObjectsForParser.h test/Parser/cxx-decl.cpp
Chris Lattner
sabre at nondot.org
Wed Dec 9 18:08:07 PST 2009
Author: lattner
Date: Wed Dec 9 20:08:07 2009
New Revision: 91040
URL: http://llvm.org/viewvc/llvm-project?rev=91040&view=rev
Log:
If we enter parens, colons can become un-sacred, allowing us to emit
a better diagnostic in the second example.
Modified:
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/RAIIObjectsForParser.h
cfe/trunk/test/Parser/cxx-decl.cpp
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=91040&r1=91039&r2=91040&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Dec 9 20:08:07 2009
@@ -565,9 +565,15 @@
TypeTy *CastTy;
SourceLocation LParenLoc = Tok.getLocation();
SourceLocation RParenLoc;
- Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
- TypeOfCast, CastTy, RParenLoc);
- if (Res.isInvalid()) return move(Res);
+
+ {
+ // The inside of the parens don't need to be a colon protected scope.
+ ColonProtectionRAIIObject X(*this, false);
+
+ Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
+ TypeOfCast, CastTy, RParenLoc);
+ if (Res.isInvalid()) return move(Res);
+ }
switch (ParenExprType) {
case SimpleExpr: break; // Nothing else to do.
Modified: cfe/trunk/lib/Parse/RAIIObjectsForParser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/RAIIObjectsForParser.h?rev=91040&r1=91039&r2=91040&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/RAIIObjectsForParser.h (original)
+++ cfe/trunk/lib/Parse/RAIIObjectsForParser.h Wed Dec 9 20:08:07 2009
@@ -48,8 +48,9 @@
Parser &P;
bool OldVal;
public:
- ColonProtectionRAIIObject(Parser &p) : P(p), OldVal(P.ColonIsSacred) {
- P.ColonIsSacred = true;
+ ColonProtectionRAIIObject(Parser &p, bool Value = true)
+ : P(p), OldVal(P.ColonIsSacred) {
+ P.ColonIsSacred = Value;
}
/// restore - This can be used to restore the state early, before the dtor
Modified: cfe/trunk/test/Parser/cxx-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-decl.cpp?rev=91040&r1=91039&r2=91040&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-decl.cpp (original)
+++ cfe/trunk/test/Parser/cxx-decl.cpp Wed Dec 9 20:08:07 2009
@@ -9,7 +9,8 @@
// PR4451 - We should recover well from the typo of '::' as ':' in a2.
namespace y {
- struct a { };
+ struct a { };
+ typedef int b;
}
y::a a1;
@@ -45,4 +46,9 @@
void test(struct Type *P) {
int Type;
Type = 1 ? P->Type : Type;
+
+ Type = (y:b) 4; // expected-error {{unexpected ':' in nested name specifier}}
+ Type = 1 ? (
+ (y:b) // expected-error {{unexpected ':' in nested name specifier}}
+ 4) : 5;
}
\ No newline at end of file
More information about the cfe-commits
mailing list