diff --git a/clang/Parse/ParseStmt.cpp b/clang/Parse/ParseStmt.cpp index 8715686e429b..c800ad0e1ff4 100644 --- a/clang/Parse/ParseStmt.cpp +++ b/clang/Parse/ParseStmt.cpp @@ -267,6 +267,8 @@ void Parser::ParseForStatement() { ConsumeToken(); } else if (isDeclarationSpecifier()) { // for (int X = 4; // Parse declaration, which eats the ';'. + if (!getLang().C99) // Use of C99-style for loops in C90 mode? + Diag(Tok, diag::ext_c99_variable_decl_in_for_loop); ParseDeclaration(Declarator::ForContext); } else { ParseExpression(); diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def index 4e910476e688..c7b0e418b20f 100644 --- a/clang/include/clang/Basic/DiagnosticKinds.def +++ b/clang/include/clang/Basic/DiagnosticKinds.def @@ -254,6 +254,8 @@ DIAG(ext_ident_list_in_param, EXTENSION, "type-less parameter names in function declaration") DIAG(ext_c99_array_usage, EXTENSION, "use of c99-specific array features") +DIAG(ext_c99_variable_decl_in_for_loop, EXTENSION, + "variable declaration in for loop is a c99-specific feature") // Generic errors. DIAG(err_parse_error, ERROR,