a local class. */
bool in_function_body;
+ /* TRUE if we can auto-correct a colon to a scope operator. */
+ bool colon_corrects_to_scope_p;
+
/* If non-NULL, then we are parsing a construct where new type
definitions are not permitted. The string stored here will be
issued as an error message if a type is defined. */
/* We are not parsing a function body. */
parser->in_function_body = false;
+ /* We can correct until told otherwise. */
+ parser->colon_corrects_to_scope_p = true;
+
/* The unparsed function queue is empty. */
push_unparsed_function_queues (parser);
template-id), nor a `::', then we are not looking at a
nested-name-specifier. */
token = cp_lexer_peek_nth_token (parser->lexer, 2);
+
+ if (token->type == CPP_COLON
+ && parser->colon_corrects_to_scope_p
+ && cp_lexer_peek_nth_token (parser->lexer, 3)->type == CPP_NAME)
+ {
+ error_at (token->location,
+ "found %<:%> in nested-name-specifier, expected %<::%>");
+ token->type = CPP_SCOPE;
+ }
+
if (token->type != CPP_SCOPE
&& !cp_parser_nth_token_starts_template_argument_list_p
(parser, 2))
}
else
{
+ bool saved_colon_corrects_to_scope_p = parser->colon_corrects_to_scope_p;
+ parser->colon_corrects_to_scope_p = false;
/* Parse the expression. */
c_inhibit_evaluation_warnings += logical_or_expr == truthvalue_false_node;
expr = cp_parser_expression (parser, /*cast_p=*/false, NULL);
c_inhibit_evaluation_warnings +=
((logical_or_expr == truthvalue_true_node)
- (logical_or_expr == truthvalue_false_node));
+ parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p;
}
/* The next token should be a `:'. */
{
cp_token *token;
tree label = NULL_TREE;
+ bool saved_colon_corrects_to_scope_p = parser->colon_corrects_to_scope_p;
/* The next token should be an identifier. */
token = cp_lexer_peek_token (parser->lexer);
return;
}
+ parser->colon_corrects_to_scope_p = false;
switch (token->keyword)
{
case RID_CASE:
else
cplus_decl_attributes (&label, attrs, 0);
}
+
+ parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p;
}
/* Parse an expression-statement.
cp_declarator *declarator;
const char *saved_message;
tree attributes, pushed_scope;
+ bool saved_colon_corrects_to_scope_p = parser->colon_corrects_to_scope_p;
+ parser->colon_corrects_to_scope_p = false;
cp_parser_parse_tentatively (parser);
/* New types are not allowed in the type-specifier-seq for a
range-based for loop. */
if (cp_parser_error_occurred (parser))
{
cp_parser_abort_tentative_parse (parser);
- return NULL_TREE;
+ stmt = NULL_TREE;
+ goto out;
}
/* Parse the declarator. */
declarator = cp_parser_declarator (parser, CP_PARSER_DECLARATOR_NAMED,
/* Convert the range-based for loop into a normal for-statement. */
stmt = cp_convert_range_for (stmt, range_decl, range_expr);
+ out:
+ parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p;
return stmt;
}
bool is_anonymous = false;
tree underlying_type = NULL_TREE;
cp_token *type_start_token = NULL;
+ bool saved_colon_corrects_to_scope_p = parser->colon_corrects_to_scope_p;
+
+ parser->colon_corrects_to_scope_p = false;
/* Parse tentatively so that we can back up if we don't find a
enum-specifier. */
{
cp_parser_error (parser, "expected %<{%>");
if (has_underlying_type)
- return NULL_TREE;
+ {
+ type = NULL_TREE;
+ goto out;
+ }
}
/* An opaque-enum-specifier must have a ';' here. */
if ((scoped_enum_p || underlying_type)
{
cp_parser_error (parser, "expected %<;%> or %<{%>");
if (has_underlying_type)
- return NULL_TREE;
+ {
+ type = NULL_TREE;
+ goto out;
+ }
}
}
pop_nested_namespace (nested_name_specifier);
}
}
+ out:
+ parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p;
return type;
}
bool qualified_p = false;
bool invalid_nested_name_p = false;
bool invalid_explicit_specialization_p = false;
+ bool saved_colon_corrects_to_scope_p = parser->colon_corrects_to_scope_p;
tree pushed_scope = NULL_TREE;
unsigned num_templates;
cp_token *type_start_token = NULL, *nested_name_specifier_token_start = NULL;
/* Assume no template parameter lists will be used in defining the
type. */
num_templates = 0;
+ parser->colon_corrects_to_scope_p = false;
*bases = NULL_TREE;
if (!cp_parser_next_token_starts_class_definition_p (parser))
{
cp_parser_error (parser, "expected %<{%> or %<:%>");
- return error_mark_node;
+ type = error_mark_node;
+ goto out;
}
/* At this point, we're going ahead with the class-specifier, even
{
cp_parser_error (parser,
"global qualification of class name is invalid");
- return error_mark_node;
+ type = error_mark_node;
+ goto out;
}
else if (invalid_nested_name_p)
{
cp_parser_error (parser,
"qualified name does not name a class");
- return error_mark_node;
+ type = error_mark_node;
+ goto out;
}
else if (nested_name_specifier)
{
if (type)
DECL_SOURCE_LOCATION (TYPE_NAME (type)) = type_start_token->location;
*attributes_p = attributes;
+ out:
+ parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p;
return type;
}
cp_token *decl_spec_token_start = NULL;
cp_token *initializer_token_start = NULL;
int saved_pedantic;
+ bool saved_colon_corrects_to_scope_p = parser->colon_corrects_to_scope_p;
/* Check for the `__extension__' keyword. */
if (cp_parser_extension_opt (parser, &saved_pedantic))
return;
}
+ parser->colon_corrects_to_scope_p = false;
+
if (cp_parser_using_declaration (parser, /*access_declaration=*/true))
- return;
+ goto out;
/* Parse the decl-specifier-seq. */
decl_spec_token_start = cp_lexer_peek_token (parser->lexer);
/* Check for an invalid type-name. */
if (!decl_specifiers.any_type_specifiers_p
&& cp_parser_parse_and_diagnose_invalid_type_name (parser))
- return;
+ goto out;
/* If there is no declarator, then the decl-specifier-seq should
specify a type. */
if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
if (cp_lexer_next_token_is (parser->lexer,
CPP_SEMICOLON))
cp_lexer_consume_token (parser->lexer);
- return;
+ goto out;
}
if (declares_class_or_enum & 2)
/* If the next token is a semicolon, consume it. */
if (token->type == CPP_SEMICOLON)
cp_lexer_consume_token (parser->lexer);
- return;
+ goto out;
}
else
if (declarator->kind == cdk_function)
}
if (assume_semicolon)
- return;
+ goto out;
}
}
cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
+ out:
+ parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p;
}
/* Parse a pure-specifier.