def err_expected_method_body : Error<"expected method body">;
def err_invalid_token_after_toplevel_declarator : Error<
"expected ';' after top level declarator">;
+def err_invalid_equalequal_after_declarator : Error<
+ "invalid '==' at end of declaration; did you mean '='?">;
def err_expected_statement : Error<"expected statement">;
def err_expected_lparen_after : Error<"expected '(' after '%0'">;
def err_expected_lparen_after_id : Error<"expected '(' after %0">;
Tok.getKind() == tok::wide_string_literal;
}
+ /// \brief Returns true if the current token is a '=' or '==' and
+ /// false otherwise. If it's '==', we assume that it's a typo and we emit
+ /// DiagID and a fixit hint to turn '==' -> '='.
+ bool isTokenEqualOrMistypedEqualEqual(unsigned DiagID);
+
/// ConsumeToken - Consume the current 'peek token' and lex the next one.
/// This does not work with all kinds of tokens: strings and specific other
/// tokens must be consumed with custom methods below. This returns the
}
// Parse declarator '=' initializer.
- if (Tok.is(tok::equal)) {
+ if (isTokenEqualOrMistypedEqualEqual(
+ diag::err_invalid_equalequal_after_declarator)) {
ConsumeToken();
if (Tok.is(tok::kw_delete)) {
SourceLocation DelLoc = ConsumeToken();
DeclaratorInfo);
DeclOut = Dcl.get();
ExprOut = ExprError();
-
+
// '=' assignment-expression
- if (Tok.is(tok::equal)) {
+ if (isTokenEqualOrMistypedEqualEqual(
+ diag::err_invalid_equalequal_after_declarator)) {
SourceLocation EqualLoc = ConsumeToken();
ExprResult AssignExpr(ParseAssignmentExpression());
if (!AssignExpr.isInvalid())
return false;
}
+bool Parser::isTokenEqualOrMistypedEqualEqual(unsigned DiagID) {
+ if (Tok.is(tok::equalequal)) {
+ // We have '==' in a context that we would expect a '='.
+ // The user probably made a typo, intending to type '='. Emit diagnostic,
+ // fixit hint to turn '==' -> '=' and continue as if the user typed '='.
+ Diag(Tok, DiagID)
+ << FixItHint::CreateReplacement(SourceRange(Tok.getLocation()),
+ getTokenSimpleSpelling(tok::equal));
+ return true;
+ }
+
+ return Tok.is(tok::equal);
+}
+
void Parser::CodeCompletionRecovery() {
for (Scope *S = getCurScope(); S; S = S->getParent()) {
if (S->getFlags() & Scope::FnScope) {
int C::foo();
};
+namespace rdar8488464 {
+int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
+
+void f() {
+ int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
+ (void)x;
+ if (int x == 0) { // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
+ (void)x;
+ }
+}
+}
+