aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/cp/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.9/gcc/cp/parser.c')
-rw-r--r--gcc-4.9/gcc/cp/parser.c148
1 files changed, 94 insertions, 54 deletions
diff --git a/gcc-4.9/gcc/cp/parser.c b/gcc-4.9/gcc/cp/parser.c
index aa00a7b68..706f6c020 100644
--- a/gcc-4.9/gcc/cp/parser.c
+++ b/gcc-4.9/gcc/cp/parser.c
@@ -1891,7 +1891,7 @@ static tree cp_parser_string_literal
static tree cp_parser_userdef_char_literal
(cp_parser *);
static tree cp_parser_userdef_string_literal
- (cp_token *);
+ (tree);
static tree cp_parser_userdef_numeric_literal
(cp_parser *);
@@ -3696,8 +3696,7 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
{
tree literal = build_userdef_literal (suffix_id, value,
OT_NONE, NULL_TREE);
- tok->u.value = literal;
- return cp_parser_userdef_string_literal (tok);
+ value = cp_parser_userdef_string_literal (literal);
}
}
else
@@ -3945,9 +3944,8 @@ cp_parser_userdef_numeric_literal (cp_parser *parser)
as arguments. */
static tree
-cp_parser_userdef_string_literal (cp_token *token)
+cp_parser_userdef_string_literal (tree literal)
{
- tree literal = token->u.value;
tree suffix_id = USERDEF_LITERAL_SUFFIX_ID (literal);
tree name = cp_literal_operator_id (IDENTIFIER_POINTER (suffix_id));
tree value = USERDEF_LITERAL_VALUE (literal);
@@ -5835,20 +5833,6 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
}
break;
}
-
- case RID_CILK_SYNC:
- if (flag_cilkplus)
- {
- tree sync_expr = build_cilk_sync ();
- SET_EXPR_LOCATION (sync_expr,
- cp_lexer_peek_token (parser->lexer)->location);
- finish_expr_stmt (sync_expr);
- }
- else
- error_at (token->location, "-fcilkplus must be enabled to use"
- " %<_Cilk_sync%>");
- cp_lexer_consume_token (parser->lexer);
- break;
case RID_BUILTIN_SHUFFLE:
{
@@ -8099,6 +8083,16 @@ cp_parser_question_colon_clause (cp_parser* parser, tree logical_or_expr)
tf_warning_or_error);
}
+/* A helpfer function to check if the given expression (EXPR) is of POD type.
+ Note that if the expression's type is NULL (e.g. when its type depends on
+ template parameters), we return false. */
+
+static bool
+expr_is_pod (tree expr)
+{
+ return TREE_TYPE (expr) && pod_type_p (TREE_TYPE (expr));
+}
+
/* Parse an assignment-expression.
assignment-expression:
@@ -8157,6 +8151,16 @@ cp_parser_assignment_expression (cp_parser* parser, bool cast_p,
if (cp_parser_non_integral_constant_expression (parser,
NIC_ASSIGNMENT))
return error_mark_node;
+
+ /* Check for and warn about self-assignment if -Wself-assign is
+ enabled and the assignment operator is "=".
+ Checking for non-POD self-assignment will be performed only
+ when -Wself-assign-non-pod is enabled. */
+ if (warn_self_assign
+ && assignment_operator == NOP_EXPR
+ && (warn_self_assign_non_pod || expr_is_pod (expr)))
+ check_for_self_assign (input_location, expr, rhs);
+
/* Build the assignment expression. Its default
location is the location of the '=' token. */
saved_input_location = input_location;
@@ -9400,6 +9404,24 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr,
statement = cp_parser_jump_statement (parser);
break;
+ case RID_CILK_SYNC:
+ cp_lexer_consume_token (parser->lexer);
+ if (flag_cilkplus)
+ {
+ tree sync_expr = build_cilk_sync ();
+ SET_EXPR_LOCATION (sync_expr,
+ token->location);
+ statement = finish_expr_stmt (sync_expr);
+ }
+ else
+ {
+ error_at (token->location, "-fcilkplus must be enabled to use"
+ " %<_Cilk_sync%>");
+ statement = error_mark_node;
+ }
+ cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
+ break;
+
/* Objective-C++ exception-handling constructs. */
case RID_AT_TRY:
case RID_AT_CATCH:
@@ -12866,6 +12888,9 @@ cp_parser_operator (cp_parser* parser)
static void
cp_parser_template_declaration (cp_parser* parser, bool member_p)
{
+ /* A hack to disable -Wself-assign warning in template parsing. */
+ int old_warn_self_assign = warn_self_assign;
+ warn_self_assign = 0;
/* Check for `export'. */
if (cp_lexer_next_token_is_keyword (parser->lexer, RID_EXPORT))
{
@@ -12876,6 +12901,7 @@ cp_parser_template_declaration (cp_parser* parser, bool member_p)
}
cp_parser_template_declaration_after_export (parser, member_p);
+ warn_self_assign = old_warn_self_assign;
}
/* Parse a template-parameter-list.
@@ -15045,6 +15071,18 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
return cp_parser_make_typename_type (parser, parser->scope,
identifier,
token->location);
+
+ /* Template parameter lists apply only if we are not within a
+ function parameter list. */
+ bool template_parm_lists_apply
+ = parser->num_template_parameter_lists;
+ if (template_parm_lists_apply)
+ for (cp_binding_level *s = current_binding_level;
+ s && s->kind != sk_template_parms;
+ s = s->level_chain)
+ if (s->kind == sk_function_parms)
+ template_parm_lists_apply = false;
+
/* Look up a qualified name in the usual way. */
if (parser->scope)
{
@@ -15087,7 +15125,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
decl = (cp_parser_maybe_treat_template_as_class
(decl, /*tag_name_p=*/is_friend
- && parser->num_template_parameter_lists));
+ && template_parm_lists_apply));
if (TREE_CODE (decl) != TYPE_DECL)
{
@@ -15100,9 +15138,9 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
if (TREE_CODE (TREE_TYPE (decl)) != TYPENAME_TYPE)
{
- bool allow_template = (parser->num_template_parameter_lists
- || DECL_SELF_REFERENCE_P (decl));
- type = check_elaborated_type_specifier (tag_type, decl,
+ bool allow_template = (template_parm_lists_apply
+ || DECL_SELF_REFERENCE_P (decl));
+ type = check_elaborated_type_specifier (tag_type, decl,
allow_template);
if (type == error_mark_node)
@@ -15188,15 +15226,16 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
ts = ts_global;
template_p =
- (parser->num_template_parameter_lists
+ (template_parm_lists_apply
&& (cp_parser_next_token_starts_class_definition_p (parser)
|| cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)));
/* An unqualified name was used to reference this type, so
there were no qualifying templates. */
- if (!cp_parser_check_template_parameters (parser,
- /*num_templates=*/0,
- token->location,
- /*declarator=*/NULL))
+ if (template_parm_lists_apply
+ && !cp_parser_check_template_parameters (parser,
+ /*num_templates=*/0,
+ token->location,
+ /*declarator=*/NULL))
return error_mark_node;
type = xref_tag (tag_type, identifier, ts, template_p);
}
@@ -16096,7 +16135,6 @@ cp_parser_alias_declaration (cp_parser* parser)
id = cp_parser_identifier (parser);
if (id == error_mark_node)
return error_mark_node;
-
cp_token *attrs_token = cp_lexer_peek_token (parser->lexer);
attributes = cp_parser_attributes_opt (parser);
if (attributes == error_mark_node)
@@ -16869,6 +16907,10 @@ cp_parser_init_declarator (cp_parser* parser,
`explicit' constructor cannot be used. */
((is_direct_init || !is_initialized)
? LOOKUP_NORMAL : LOOKUP_IMPLICIT));
+ /* Check for and warn about self-initialization if -Wself-assign is
+ enabled. */
+ if (warn_self_assign && initializer)
+ check_for_self_assign (input_location, decl, initializer);
}
else if ((cxx_dialect != cxx98) && friend_p
&& decl && TREE_CODE (decl) == FUNCTION_DECL)
@@ -17837,7 +17879,7 @@ cp_parser_virt_specifier_seq_opt (cp_parser* parser)
/* Used by handling of trailing-return-types and NSDMI, in which 'this'
is in scope even though it isn't real. */
-static void
+void
inject_this_parameter (tree ctype, cp_cv_quals quals)
{
tree this_parm;
@@ -23090,10 +23132,17 @@ cp_parser_template_declaration_after_export (cp_parser* parser, bool member_p)
ok = false;
}
if (!ok)
- error ("literal operator template %qD has invalid parameter list."
- " Expected non-type template argument pack <char...>"
- " or <typename CharT, CharT...>",
- decl);
+ {
+ if (cxx_dialect >= cxx1y)
+ error ("literal operator template %qD has invalid parameter list."
+ " Expected non-type template argument pack <char...>"
+ " or <typename CharT, CharT...>",
+ decl);
+ else
+ error ("literal operator template %qD has invalid parameter list."
+ " Expected non-type template argument pack <char...>",
+ decl);
+ }
}
/* Register member declarations. */
if (member_p && !friend_p && decl && !DECL_CLASS_TEMPLATE_P (decl))
@@ -23664,16 +23713,7 @@ cp_parser_late_parse_one_default_arg (cp_parser *parser, tree decl,
parsed_arg = check_default_argument (parmtype, parsed_arg,
tf_warning_or_error);
else
- {
- int flags = LOOKUP_IMPLICIT;
- if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg)
- && CONSTRUCTOR_IS_DIRECT_INIT (parsed_arg))
- flags = LOOKUP_NORMAL;
- parsed_arg = digest_init_flags (TREE_TYPE (decl), parsed_arg, flags);
- if (TREE_CODE (parsed_arg) == TARGET_EXPR)
- /* This represents the whole initialization. */
- TARGET_EXPR_DIRECT_INIT_P (parsed_arg) = true;
- }
+ parsed_arg = digest_nsdmi_init (decl, parsed_arg);
}
/* If the token stream has not been completely used up, then
@@ -29361,9 +29401,17 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses,
change it to shared (decl) in OMP_PARALLEL_CLAUSES. */
tree l = build_omp_clause (loc, OMP_CLAUSE_LASTPRIVATE);
OMP_CLAUSE_DECL (l) = real_decl;
- OMP_CLAUSE_CHAIN (l) = clauses;
CP_OMP_CLAUSE_INFO (l) = CP_OMP_CLAUSE_INFO (*c);
- clauses = l;
+ if (code == OMP_SIMD)
+ {
+ OMP_CLAUSE_CHAIN (l) = cclauses[C_OMP_CLAUSE_SPLIT_FOR];
+ cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l;
+ }
+ else
+ {
+ OMP_CLAUSE_CHAIN (l) = clauses;
+ clauses = l;
+ }
OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED);
CP_OMP_CLAUSE_INFO (*c) = NULL;
add_private_clause = false;
@@ -31667,14 +31715,6 @@ pragma_lex (tree *value)
void
c_parse_file (void)
{
- static bool already_called = false;
-
- if (already_called)
- {
- sorry ("inter-module optimizations not implemented for C++");
- return;
- }
- already_called = true;
the_parser = cp_parser_new ();
push_deferring_access_checks (flag_access_control