summaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authordnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-03-26 10:33:36 +0000
committerdnovillo <dnovillo@138bc75d-0d04-0410-961f-82ee72b054a4>2013-03-26 10:33:36 +0000
commita63f89638edc7c3120e52faf6815bfe3e9b270e2 (patch)
tree61b7552b10852929b89f1cb93878fadffc1885c2 /gcc/cp
parent9402409a6bd0d7d1f7358793f768bda3ec8a9574 (diff)
parent087a99ba8749638f86c111f776ed326b3fbd97c0 (diff)
downloadgcc-cxx-conversion.tar.gz
Merged revisions 196607-196608,196611-196614,196625,196629-196634,196636,196639,196645-196647,196649-196650,196654-196659,196666,196669,196671-196675,196682-196683,196694-196695,196697-196698,196700-196701,196704-196706,196709,196721-196748,196750-196751,196753,196755-196758,196762,196764-196765,196767-196771,196773-196779,196781-196784,196788-196792,196795-196797,196799-196800,196804-196807,196810-196814,196821,196823-196825,196828-196829,196831-196832,196834,196841-196842,196847-196853,196855-196856,196858,196860-196861,196864-196866,196868,196870-196872,196874,196876,196878-196879,196882,196884-196890,196896-196897,196899-196902,196954,196956-196961,196964-196965,196970,196977-196978,196981-196983,196989,197002-197005,197007,197011-197012,197016-197019,197021,197023-197025,197029-197034,197036-197042 via svnmerge from cxx-conversion
svn+ssh://gcc.gnu.org/svn/gcc/trunk git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/cxx-conversion@197098 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog235
-rw-r--r--gcc/cp/call.c66
-rw-r--r--gcc/cp/class.c10
-rw-r--r--gcc/cp/cp-tree.h46
-rw-r--r--gcc/cp/decl.c107
-rw-r--r--gcc/cp/decl2.c2
-rw-r--r--gcc/cp/error.c18
-rw-r--r--gcc/cp/except.c12
-rw-r--r--gcc/cp/expr.c4
-rw-r--r--gcc/cp/init.c4
-rw-r--r--gcc/cp/mangle.c6
-rw-r--r--gcc/cp/method.c17
-rw-r--r--gcc/cp/name-lookup.c22
-rw-r--r--gcc/cp/name-lookup.h3
-rw-r--r--gcc/cp/parser.c243
-rw-r--r--gcc/cp/pt.c178
-rw-r--r--gcc/cp/search.c12
-rw-r--r--gcc/cp/semantics.c56
-rw-r--r--gcc/cp/tree.c13
-rw-r--r--gcc/cp/typeck.c26
-rw-r--r--gcc/cp/typeck2.c99
21 files changed, 874 insertions, 305 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c728c50c587..0a943a13537 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,238 @@
+2013-03-22 Jason Merrill <jason@redhat.com>
+
+ PR c++/56684
+ * pt.c (instantiation_dependent_r): Check DECL_INITIAL of VAR_DECL
+ and CONST_DECL.
+
+2013-03-21 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
+ * cp-tree.h (identifier_p): New.
+ * call.c: Throughout, call identifier_p insstead of direct
+ comparaison of TREE_CODE against IDENTIFIER_NODE.
+ * decl.c: Likewisse.
+ * decl2.c: Likewise.
+ * init.c: Likewise.
+ * mangle.c: Likewise.
+ * name-lookup.c: Likewise.
+ * parser.c: Likewise.
+ * pt.c: Likewise.
+ * search.c: Likewise.
+ * semantics.c: Likewise.
+ * tree.c: Likewise.
+ * typeck.c: Likewise.
+ * typeck2.c: Likewise.
+
+2013-03-21 Jakub Jelinek <jakub@redhat.com>
+
+ PR middle-end/48087
+ * pt.c (convert_nontype_argument): Count werrorcount as warnings.
+ * call.c (build_temp): Likewise.
+ * method.c (synthesize_method): Likewise.
+ * typeck.c (convert_for_initialization): Likewise.
+
+2013-03-21 Marc Glisse <marc.glisse@inria.fr>
+
+ * call.c (build_conditional_expr_1): Fold VEC_COND_EXPR.
+
+2013-03-21 Richard Biener <rguenther@suse.de>
+
+ * error.c (cp_printer): Use DECL_HAS_DEBUG_EXPR_P instead of
+ DECL_DEBUG_EXPR_IS_FROM. Guard properly.
+
+2013-03-20 Jason Merrill <jason@redhat.com>
+
+ PR c++/56646
+ * parser.c (cp_parser_late_return_type_opt): Save and restore
+ current_class_ptr/ref.
+
+ PR c++/54532
+ * expr.c (cplus_expand_constant): Do nothing if the class is
+ incomplete.
+ * semantics.c (reduced_constant_expression_p): Allow PTRMEM_CST.
+ * typeck2.c (store_init_value): Use reduced_constant_expression_p.
+ * decl.c (maybe_register_incomplete_var): Handle PTRMEM_CST.
+ (complete_vars): Likewise.
+
+ * name-lookup.c (get_anonymous_namespace_name): Never use
+ get_file_function_name.
+
+ * pt.c (retrieve_specialization): Handle null tmpl argument.
+
+ PR c++/17232
+ PR c++/56642
+ * pt.c (tsubst_decl): Check return value of register_specialization.
+ * typeck2.c (abstract_virtuals_error_sfinae): Re-apply complete_type
+ change.
+
+2013-03-17 Jason Merrill <jason@redhat.com>
+
+ PR c++/54359
+ PR c++/56639
+ * parser.c (cp_parser_direct_declarator): Bail if we see a
+ qualified-id not at namespace scope.
+
+ PR c++/17232
+ PR c++/56642
+ * typeck2.c (abstract_virtuals_error_sfinae): Revert complete_type
+ change for now.
+
+2013-03-16 Jason Merrill <jason@redhat.com>
+
+ * decl.c (grokdeclarator): Assert that we won't see a pointer to
+ METHOD_TYPE.
+
+ PR c++/54277
+ * cp-tree.h (WILDCARD_TYPE_P): Split out from...
+ (MAYBE_CLASS_TYPE_P): ...here.
+ * semantics.c (lambda_capture_field_type): Only build a
+ magic decltype for wildcard types.
+ (lambda_proxy_type): Likewise.
+ (finish_non_static_data_member): Get the quals from
+ the object.
+
+ PR c++/55931
+ * parser.c (cp_parser_template_argument): Don't
+ fold_non_dependent_expr.
+
+ * parser.c (cp_parser_lambda_declarator_opt): Use
+ cp_parser_trailing_type_id.
+
+ PR c++/45917
+ * parser.c (cp_parser_template_id): Don't forget access checks.
+
+ PR c++/52374
+ * pt.c (tsubst_qualified_id): Use current_nonlambda_class_type.
+
+ PR c++/54764
+ PR c++/55972
+ * name-lookup.h (tag_scope): Add ts_lambda.
+ * semantics.c (begin_lambda_type): Use it.
+ * decl.c (xref_tag_1): Set CLASSTYPE_LAMBDA_EXPR.
+ * pt.c (check_default_tmpl_args): Ignore lambdas.
+ (push_template_decl_real): Handle lambdas.
+ * tree.c (no_linkage_check): Adjust lambda check.
+
+ PR c++/56039
+ * tree.c (strip_typedefs_expr): Complain about lambda, don't abort.
+
+ PR c++/54359
+ * parser.c (cp_parser_direct_declarator): Fix late return
+ for out-of-class defn of member function.
+
+ PR c++/55357
+ * semantics.c (maybe_add_lambda_conv_op): Clear DECL_NAME of copied
+ parms to avoid duplicate -Wshadow warnings.
+
+ * search.c (lookup_base): Handle NULL_TREE.
+
+ PR c++/56481
+ * semantics.c (potential_constant_expression_1): Use of 'this' in
+ a non-constexpr function makes the expression not potentially
+ constant.
+
+ N3276
+ PR c++/52748
+ * cp-tree.h (tsubst_flags): Add tf_decltype.
+ * call.c (build_cxx_call): Don't build a temporary if it's set.
+ (build_over_call): Make sure it's only passed to build_cxx_call.
+ * parser.c (cp_parser_primary_expression): Add decltype_p parm.
+ (cp_parser_unary_expression): Likewise.
+ (cp_parser_cast_expression): Likewise.
+ (cp_parser_binary_expression): Likewise.
+ (cp_parser_assignment_expression): Likewise.
+ (cp_parser_postfix_expression): Likewise. Pass tf_decltype.
+ (cp_parser_expression): Add decltype_p. Force a
+ temporary for a call on the LHS of a comma.
+ (cp_parser_decltype): Pass true to decltype_p parms.
+ * pt.c (tsubst) [DECLTYPE_TYPE]: Pass tf_decltype.
+ (tsubst_copy_and_build): Pass tf_decltype down only for
+ CALL_EXPR and the RHS of COMPOUND_EXPR.
+ * tree.c (build_cplus_new): Call complete_type_or_maybe_complain.
+
+ * cp-tree.h (abstract_class_use): New enum.
+ * typeck2.c (pending_abstract_type): Add use field.
+ (abstract_virtuals_error_sfinae): Add overloads taking
+ abstract_class_use instead of tree.
+ * typeck.c (build_static_cast_1): Call it.
+ * except.c (is_admissible_throw_operand_or_catch_parameter): Call it.
+ * pt.c: Adjust calls.
+ * decl.c (cp_finish_decl): Don't handle functions specially.
+ (grokdeclarator): Always check return type.
+ * init.c (build_new_1): Adjust call.
+
+ DR 337
+ PR c++/17232
+ * pt.c (tsubst) [ARRAY_TYPE]: Use abstract_virtuals_error_sfinae.
+ * typeck2.c (abstract_virtuals_error_sfinae): Call complete_type.
+
+ DR 657
+ * pt.c (tsubst_function_type): Call abstract_virtuals_error_sfinae.
+ (tsubst_arg_types): Likewise.
+
+ DR 1518
+ PR c++/54835
+ * call.c (convert_like_real): Check for explicit constructors
+ even for value-initialization.
+
+ PR c++/54946
+ * pt.c (convert_nontype_argument): Handle invalid pointer.
+
+ * parser.c (cp_parser_lambda_expression): Use nreverse.
+
+ PR c++/56447
+ PR c++/55532
+ * pt.c (instantiate_class_template_1): Instantiate lambda capture
+ list here.
+ (tsubst_copy_and_build): Not here.
+
+ PR c++/55017
+ * method.c (walk_field_subobs): Disallow copy of rvalue ref.
+
+ PR c++/55240
+ * parser.c (parsing_nsdmi): New.
+ * semantics.c (outer_automatic_var_p): Check it.
+ (finish_id_expression): Likewise.
+ * cp-tree.h: Declare it.
+
+ PR c++/55241
+ * error.c (dump_expr) [SIZEOF_EXPR]: Print sizeof... properly.
+
+ * parser.c (lookup_literal_operator): Correct parm/arg naming
+ mixup.
+
+ PR c++/56238
+ * pt.c (fold_non_dependent_expr_sfinae): Check
+ instantiation_dependent_expression_p.
+
+ PR c++/56095
+ * class.c (resolve_address_of_overloaded_function): Accept a
+ reference to function for target_type.
+ (instantiate_type): Likewise.
+ * pt.c (convert_nontype_argument): Pass it to
+ convert_nontype_argument_function.
+
+2013-03-16 Jakub Jelinek <jakub@redhat.com>
+
+ * tree.c (cp_tree_equal): Fix a pasto.
+
+ PR c++/56607
+ * typeck.c (cp_build_binary_op): When calling warn_for_div_by_zero,
+ pass op1 through maybe_constant_value first.
+
+2013-03-16 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/56582
+ * semantics.c (cxx_eval_array_reference): Check for negative index.
+
+2013-03-14 Jason Merrill <jason@redhat.com>
+
+ PR c++/56614
+ * decl.c (local_variable_p_walkfn): Check DECL_ARTIFICIAL again.
+
+ PR c++/56346
+ * decl.c (register_dtor_fn): Pass null to __cxa_thread_atexit
+ dso_handle parm on targets without __cxa_atexit.
+
2013-03-11 Jason Merrill <jason@redhat.com>
PR c++/56567
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 530835b87c8..dd19e48ed18 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -233,7 +233,7 @@ check_dtor_name (tree basetype, tree name)
name = TREE_TYPE (name);
else if (TYPE_P (name))
/* OK */;
- else if (TREE_CODE (name) == IDENTIFIER_NODE)
+ else if (identifier_p (name))
{
if ((MAYBE_CLASS_TYPE_P (basetype)
&& name == constructor_name (basetype))
@@ -3147,7 +3147,7 @@ print_z_candidate (location_t loc, const char *msgstr,
: ACONCAT ((msgstr, " ", NULL)));
location_t cloc = location_of (candidate->fn);
- if (TREE_CODE (candidate->fn) == IDENTIFIER_NODE)
+ if (identifier_p (candidate->fn))
{
cloc = loc;
if (candidate->num_convs == 3)
@@ -4437,9 +4437,9 @@ build_conditional_expr_1 (tree arg1, tree arg2, tree arg3,
}
if (!COMPARISON_CLASS_P (arg1))
- arg1 = build2 (NE_EXPR, signed_type_for (arg1_type), arg1,
+ arg1 = fold_build2 (NE_EXPR, signed_type_for (arg1_type), arg1,
build_zero_cst (arg1_type));
- return build3 (VEC_COND_EXPR, arg2_type, arg1, arg2, arg3);
+ return fold_build3 (VEC_COND_EXPR, arg2_type, arg1, arg2, arg3);
}
/* [expr.cond]
@@ -5709,12 +5709,12 @@ build_temp (tree expr, tree type, int flags,
int savew, savee;
vec<tree, va_gc> *args;
- savew = warningcount, savee = errorcount;
+ savew = warningcount + werrorcount, savee = errorcount;
args = make_tree_vector_single (expr);
expr = build_special_member_call (NULL_TREE, complete_ctor_identifier,
&args, type, flags, complain);
release_tree_vector (args);
- if (warningcount > savew)
+ if (warningcount + werrorcount > savew)
*diagnostic_kind = DK_WARNING;
else if (errorcount > savee)
*diagnostic_kind = DK_ERROR;
@@ -5856,6 +5856,17 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
tree convfn = cand->fn;
unsigned i;
+ /* When converting from an init list we consider explicit
+ constructors, but actually trying to call one is an error. */
+ if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
+ /* Unless this is for direct-list-initialization. */
+ && !(BRACE_ENCLOSED_INITIALIZER_P (expr)
+ && CONSTRUCTOR_IS_DIRECT_INIT (expr)))
+ {
+ error ("converting to %qT from initializer list would use "
+ "explicit constructor %qD", totype, convfn);
+ }
+
/* If we're initializing from {}, it's value-initialization. */
if (BRACE_ENCLOSED_INITIALIZER_P (expr)
&& CONSTRUCTOR_NELTS (expr) == 0
@@ -5874,20 +5885,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
expr = mark_rvalue_use (expr);
- /* When converting from an init list we consider explicit
- constructors, but actually trying to call one is an error. */
- if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
- /* Unless this is for direct-list-initialization. */
- && !(BRACE_ENCLOSED_INITIALIZER_P (expr)
- && CONSTRUCTOR_IS_DIRECT_INIT (expr))
- /* Unless we're calling it for value-initialization from an
- empty list, since that is handled separately in 8.5.4. */
- && cand->num_convs > 0)
- {
- error ("converting to %qT from initializer list would use "
- "explicit constructor %qD", totype, convfn);
- }
-
/* Set user_conv_p on the argument conversions, so rvalue/base
handling knows not to allow any more UDCs. */
for (i = 0; i < cand->num_convs; ++i)
@@ -6696,6 +6693,10 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
/* else continue to get conversion error. */
}
+ /* N3276 magic doesn't apply to nested calls. */
+ int decltype_flag = (complain & tf_decltype);
+ complain &= ~tf_decltype;
+
/* Find maximum size of vector to hold converted arguments. */
parmlen = list_length (parm);
nargs = vec_safe_length (args) + (first_arg != NULL_TREE ? 1 : 0);
@@ -7067,7 +7068,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
return error_mark_node;
}
- return build_cxx_call (fn, nargs, argarray, complain);
+ return build_cxx_call (fn, nargs, argarray, complain|decltype_flag);
}
/* Build and return a call to FN, using NARGS arguments in ARGARRAY.
@@ -7109,12 +7110,20 @@ build_cxx_call (tree fn, int nargs, tree *argarray,
if (VOID_TYPE_P (TREE_TYPE (fn)))
return fn;
- fn = require_complete_type_sfinae (fn, complain);
- if (fn == error_mark_node)
- return error_mark_node;
+ /* 5.2.2/11: If a function call is a prvalue of object type: if the
+ function call is either the operand of a decltype-specifier or the
+ right operand of a comma operator that is the operand of a
+ decltype-specifier, a temporary object is not introduced for the
+ prvalue. The type of the prvalue may be incomplete. */
+ if (!(complain & tf_decltype))
+ {
+ fn = require_complete_type_sfinae (fn, complain);
+ if (fn == error_mark_node)
+ return error_mark_node;
- if (MAYBE_CLASS_TYPE_P (TREE_TYPE (fn)))
- fn = build_cplus_new (TREE_TYPE (fn), fn, complain);
+ if (MAYBE_CLASS_TYPE_P (TREE_TYPE (fn)))
+ fn = build_cplus_new (TREE_TYPE (fn), fn, complain);
+ }
return convert_from_reference (fn);
}
@@ -8554,8 +8563,7 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn,
- do not have the same parameter type list as any non-template
non-member candidate. */
- if (TREE_CODE (cand1->fn) == IDENTIFIER_NODE
- || TREE_CODE (cand2->fn) == IDENTIFIER_NODE)
+ if (identifier_p (cand1->fn) || identifier_p (cand2->fn))
{
for (i = 0; i < len; ++i)
if (!same_type_p (cand1->convs[i]->type,
@@ -8566,7 +8574,7 @@ joust (struct z_candidate *cand1, struct z_candidate *cand2, bool warn,
if (cand1->fn == cand2->fn)
/* Two built-in candidates; arbitrarily pick one. */
return 1;
- else if (TREE_CODE (cand1->fn) == IDENTIFIER_NODE)
+ else if (identifier_p (cand1->fn))
/* cand1 is built-in; prefer cand2. */
return -1;
else
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 746c29d2dea..b48b353d596 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -7148,7 +7148,8 @@ resolve_address_of_overloaded_function (tree target_type,
gcc_assert (is_overloaded_fn (overload));
/* Check that the TARGET_TYPE is reasonable. */
- if (TYPE_PTRFN_P (target_type))
+ if (TYPE_PTRFN_P (target_type)
+ || TYPE_REFFN_P (target_type))
/* This is OK. */;
else if (TYPE_PTRMEMFUNC_P (target_type))
/* This is OK, too. */
@@ -7419,10 +7420,11 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
{
- if (same_type_p (lhstype, TREE_TYPE (rhs)))
+ tree fntype = non_reference (lhstype);
+ if (same_type_p (fntype, TREE_TYPE (rhs)))
return rhs;
if (flag_ms_extensions
- && TYPE_PTRMEMFUNC_P (lhstype)
+ && TYPE_PTRMEMFUNC_P (fntype)
&& !TYPE_PTRMEMFUNC_P (TREE_TYPE (rhs)))
/* Microsoft allows `A::f' to be resolved to a
pointer-to-member. */
@@ -7431,7 +7433,7 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
{
if (flags & tf_error)
error ("cannot convert %qE from type %qT to type %qT",
- rhs, TREE_TYPE (rhs), lhstype);
+ rhs, TREE_TYPE (rhs), fntype);
return error_mark_node;
}
}
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index c3b2aecf3b1..401868549cd 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -241,6 +241,16 @@ struct GTY(()) lang_identifier {
tree label_value;
};
+/* Return a typed pointer version of T if it designates a
+ C++ front-end identifier. */
+inline lang_identifier*
+identifier_p (tree t)
+{
+ if (TREE_CODE (t) == IDENTIFIER_NODE)
+ return (lang_identifier*) t;
+ return NULL;
+}
+
/* In an IDENTIFIER_NODE, nonzero if this identifier is actually a
keyword. C_RID_CODE (node) is then the RID_* value of the keyword,
and C_RID_YYCODE is the token number wanted by Yacc. */
@@ -463,6 +473,19 @@ typedef enum impl_conv_void {
ICV_THIRD_IN_FOR /* for increment expression */
} impl_conv_void;
+/* Possible invalid uses of an abstract class that might not have a
+ specific associated declaration. */
+typedef enum abstract_class_use {
+ ACU_UNKNOWN, /* unknown or decl provided */
+ ACU_CAST, /* cast to abstract class */
+ ACU_NEW, /* new-expression of abstract class */
+ ACU_THROW, /* throw-expression of abstract class */
+ ACU_CATCH, /* catch-parameter of abstract class */
+ ACU_ARRAY, /* array of abstract class */
+ ACU_RETURN, /* return type of abstract class */
+ ACU_PARM /* parameter type of abstract class */
+} abstract_class_use;
+
/* Macros for access to language-specific slots in an identifier. */
#define IDENTIFIER_NAMESPACE_BINDINGS(NODE) \
@@ -1207,17 +1230,20 @@ enum languages { lang_c, lang_cplusplus, lang_java };
/* The _DECL for this _TYPE. */
#define TYPE_MAIN_DECL(NODE) (TYPE_STUB_DECL (TYPE_MAIN_VARIANT (NODE)))
-/* Nonzero if T is a class (or struct or union) type. Also nonzero
- for template type parameters, typename types, and instantiated
- template template parameters. Keep these checks in ascending code
- order. */
-#define MAYBE_CLASS_TYPE_P(T) \
+/* Nonzero if T is a type that could resolve to any kind of concrete type
+ at instantiation time. */
+#define WILDCARD_TYPE_P(T) \
(TREE_CODE (T) == TEMPLATE_TYPE_PARM \
|| TREE_CODE (T) == TYPENAME_TYPE \
|| TREE_CODE (T) == TYPEOF_TYPE \
|| TREE_CODE (T) == BOUND_TEMPLATE_TEMPLATE_PARM \
- || TREE_CODE (T) == DECLTYPE_TYPE \
- || CLASS_TYPE_P (T))
+ || TREE_CODE (T) == DECLTYPE_TYPE)
+
+/* Nonzero if T is a class (or struct or union) type. Also nonzero
+ for template type parameters, typename types, and instantiated
+ template template parameters. Keep these checks in ascending code
+ order. */
+#define MAYBE_CLASS_TYPE_P(T) (WILDCARD_TYPE_P (T) || CLASS_TYPE_P (T))
/* Set CLASS_TYPE_P for T to VAL. T must be a class, struct, or
union type. */
@@ -4190,6 +4216,9 @@ enum tsubst_flags {
conversion might be permissible,
not actually performing the
conversion. */
+ tf_decltype = 1 << 7, /* We are the operand of decltype.
+ Used to implement the special rules
+ for calls in decltype (5.2.2/11). */
tf_partial = 1 << 8, /* Doing initial explicit argument
substitution in fn_type_unification. */
/* Convenient substitution flags combinations. */
@@ -4259,6 +4288,7 @@ extern int comparing_specializations;
extern int cp_unevaluated_operand;
extern tree cp_convert_range_for (tree, tree, tree);
+extern bool parsing_nsdmi (void);
/* in pt.c */
@@ -5982,7 +6012,9 @@ extern tree binfo_or_else (tree, tree);
extern void cxx_readonly_error (tree, enum lvalue_use);
extern void complete_type_check_abstract (tree);
extern int abstract_virtuals_error (tree, tree);
+extern int abstract_virtuals_error (abstract_class_use, tree);
extern int abstract_virtuals_error_sfinae (tree, tree, tsubst_flags_t);
+extern int abstract_virtuals_error_sfinae (abstract_class_use, tree, tsubst_flags_t);
extern tree store_init_value (tree, tree, vec<tree, va_gc>**, int);
extern void check_narrowing (tree, tree);
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 150e8662a5e..ea1a08d2674 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3296,7 +3296,7 @@ make_typename_type (tree context, tree name, enum tag_types tag_type,
error ("%qD used without template parameters", name);
return error_mark_node;
}
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (name));
gcc_assert (TYPE_P (context));
if (!MAYBE_CLASS_TYPE_P (context))
@@ -3402,7 +3402,7 @@ make_unbound_class_template (tree context, tree name, tree parm_list,
name = TYPE_IDENTIFIER (name);
else if (DECL_P (name))
name = DECL_NAME (name);
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (name));
if (!dependent_type_p (context)
|| currently_open_class (context))
@@ -4781,7 +4781,7 @@ check_array_designated_initializer (const constructor_elt *ce,
}
else
{
- gcc_assert (TREE_CODE (ce->index) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (ce->index));
error ("name %qD used in a GNU-style designated "
"initializer for an array", ce->index);
}
@@ -6434,11 +6434,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
/* Check for abstractness of the type. Notice that there is no
need to strip array types here since the check for those types
is already done within create_array_type_for_decl. */
- if (TREE_CODE (type) == FUNCTION_TYPE
- || TREE_CODE (type) == METHOD_TYPE)
- abstract_virtuals_error (decl, TREE_TYPE (type));
- else
- abstract_virtuals_error (decl, type);
+ abstract_virtuals_error (decl, type);
if (TREE_TYPE (decl) == error_mark_node)
/* No initialization required. */
@@ -6758,10 +6754,9 @@ register_dtor_fn (tree decl)
"__aeabi_atexit"), and DECL is a class object, we can just pass the
destructor to "__cxa_atexit"; we don't have to build a temporary
function to do the cleanup. */
- ob_parm = (DECL_THREAD_LOCAL_P (decl)
- || (flag_use_cxa_atexit
- && !targetm.cxx.use_atexit_for_cxa_atexit ()));
- dso_parm = ob_parm;
+ dso_parm = (flag_use_cxa_atexit
+ && !targetm.cxx.use_atexit_for_cxa_atexit ());
+ ob_parm = (DECL_THREAD_LOCAL_P (decl) || dso_parm);
use_dtor = ob_parm && CLASS_TYPE_P (type);
if (use_dtor)
{
@@ -6825,7 +6820,7 @@ register_dtor_fn (tree decl)
before passing it in, to avoid spurious errors. */
addr = build_nop (ptr_type_node, addr);
}
- else if (ob_parm)
+ else
/* Since the cleanup functions we build ignore the address
they're given, there's no reason to pass the actual address
in, and, in general, it's cheaper to pass NULL than any
@@ -6835,6 +6830,10 @@ register_dtor_fn (tree decl)
if (dso_parm)
arg2 = cp_build_addr_expr (get_dso_handle_node (),
tf_warning_or_error);
+ else if (ob_parm)
+ /* Just pass NULL to the dso handle parm if we don't actually
+ have a DSO handle on this target. */
+ arg2 = null_pointer_node;
else
arg2 = NULL_TREE;
@@ -7414,8 +7413,7 @@ grokfndecl (tree ctype,
== current_class_type);
fns = TREE_OPERAND (fns, 1);
}
- gcc_assert (TREE_CODE (fns) == IDENTIFIER_NODE
- || TREE_CODE (fns) == OVERLOAD);
+ gcc_assert (identifier_p (fns) || TREE_CODE (fns) == OVERLOAD);
DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
@@ -7773,7 +7771,7 @@ grokvardecl (tree type,
tree decl;
tree explicit_scope;
- gcc_assert (!name || TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (!name || identifier_p (name));
/* Compute the scope in which to place the variable, but remember
whether or not that scope was explicitly specified by the user. */
@@ -8510,7 +8508,7 @@ check_var_type (tree identifier, tree type)
{
if (!identifier)
error ("unnamed variable or field declared void");
- else if (TREE_CODE (identifier) == IDENTIFIER_NODE)
+ else if (identifier_p (identifier))
{
gcc_assert (!IDENTIFIER_OPNAME_P (identifier));
error ("variable or field %qE declared void", identifier);
@@ -8653,6 +8651,7 @@ grokdeclarator (const cp_declarator *declarator,
bool template_type_arg = false;
bool template_parm_flag = false;
bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
+ source_location saved_loc = input_location;
const char *errmsg;
signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
@@ -8778,7 +8777,7 @@ grokdeclarator (const cp_declarator *declarator,
tree fns = TREE_OPERAND (decl, 0);
dname = fns;
- if (TREE_CODE (dname) != IDENTIFIER_NODE)
+ if (!identifier_p (dname))
{
gcc_assert (is_overloaded_fn (dname));
dname = DECL_NAME (get_first_fn (dname));
@@ -8787,7 +8786,7 @@ grokdeclarator (const cp_declarator *declarator,
/* Fall through. */
case IDENTIFIER_NODE:
- if (TREE_CODE (decl) == IDENTIFIER_NODE)
+ if (identifier_p (decl))
dname = decl;
if (C_IS_RESERVED_WORD (dname))
@@ -8852,7 +8851,7 @@ grokdeclarator (const cp_declarator *declarator,
}
if (dname
- && TREE_CODE (dname) == IDENTIFIER_NODE
+ && identifier_p (dname)
&& UDLIT_OPER_P (dname)
&& innermost_code != cdk_function)
{
@@ -8977,7 +8976,7 @@ grokdeclarator (const cp_declarator *declarator,
common. With no options, it is allowed. With -Wreturn-type,
it is a warning. It is only an error with -pedantic-errors. */
is_main = (funcdef_flag
- && dname && TREE_CODE (dname) == IDENTIFIER_NODE
+ && dname && identifier_p (dname)
&& MAIN_NAME_P (dname)
&& ctype == NULL_TREE
&& in_namespace == NULL_TREE
@@ -9337,7 +9336,6 @@ grokdeclarator (const cp_declarator *declarator,
if (declspecs->std_attributes)
{
/* Apply the c++11 attributes to the type preceding them. */
- source_location saved_loc = input_location;
input_location = declspecs->locations[ds_std_attribute];
decl_attributes (&type, declspecs->std_attributes, 0);
input_location = saved_loc;
@@ -9425,11 +9423,10 @@ grokdeclarator (const cp_declarator *declarator,
error ("%qs declared as function returning an array", name);
return error_mark_node;
}
- /* When decl_context == NORMAL we emit a better error message
- later in abstract_virtuals_error. */
- if (decl_context == TYPENAME && ABSTRACT_CLASS_TYPE_P (type))
- error ("%qs declared as function returning an abstract "
- "class type", name);
+
+ input_location = declspecs->locations[ds_type_spec];
+ abstract_virtuals_error (ACU_RETURN, type);
+ input_location = saved_loc;
/* Pick up type qualifiers which should be applied to `this'. */
memfn_quals = declarator->u.function.qualifiers;
@@ -9632,9 +9629,11 @@ grokdeclarator (const cp_declarator *declarator,
but to the target of the pointer. */
type_quals = TYPE_UNQUALIFIED;
+ /* This code used to handle METHOD_TYPE, but I don't think it's
+ possible to get it here anymore. */
+ gcc_assert (TREE_CODE (type) != METHOD_TYPE);
if (declarator->kind == cdk_ptrmem
- && (TREE_CODE (type) == FUNCTION_TYPE
- || (memfn_quals && TREE_CODE (type) == METHOD_TYPE)))
+ && TREE_CODE (type) == FUNCTION_TYPE)
{
memfn_quals |= type_memfn_quals (type);
type = build_memfn_type (type,
@@ -10800,9 +10799,8 @@ static tree
local_variable_p_walkfn (tree *tp, int *walk_subtrees,
void * /*data*/)
{
- /* Check DECL_NAME to avoid including temporaries. We don't check
- DECL_ARTIFICIAL because we do want to complain about 'this'. */
- if (local_variable_p (*tp) && DECL_NAME (*tp))
+ if (local_variable_p (*tp)
+ && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
return *tp;
else if (TYPE_P (*tp))
*walk_subtrees = 0;
@@ -11890,13 +11888,14 @@ lookup_and_check_tag (enum tag_types tag_code, tree name,
static tree
xref_tag_1 (enum tag_types tag_code, tree name,
- tag_scope scope, bool template_header_p)
+ tag_scope orig_scope, bool template_header_p)
{
enum tree_code code;
tree t;
tree context = NULL_TREE;
+ tag_scope scope;
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (name));
switch (tag_code)
{
@@ -11914,6 +11913,11 @@ xref_tag_1 (enum tag_types tag_code, tree name,
gcc_unreachable ();
}
+ if (orig_scope == ts_lambda)
+ scope = ts_current;
+ else
+ scope = orig_scope;
+
/* In case of anonymous name, xref_tag is only called to
make type node and push name. Name lookup is not required. */
if (ANON_AGGRNAME_P (name))
@@ -11987,6 +11991,10 @@ xref_tag_1 (enum tag_types tag_code, tree name,
{
t = make_class_type (code);
TYPE_CONTEXT (t) = context;
+ if (orig_scope == ts_lambda)
+ /* Remember that we're declaring a lambda to avoid bogus errors
+ in push_template_decl. */
+ CLASSTYPE_LAMBDA_EXPR (t) = error_mark_node;
t = pushtag (name, t, scope);
}
}
@@ -12314,7 +12322,7 @@ start_enum (tree name, tree enumtype, tree underlying_type,
bool scoped_enum_p, bool *is_new)
{
tree prevtype = NULL_TREE;
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (name));
if (is_new)
*is_new = false;
@@ -14009,7 +14017,10 @@ grokmethod (cp_decl_specifier_seq *declspecs,
/* VAR is a VAR_DECL. If its type is incomplete, remember VAR so that
- we can lay it out later, when and if its type becomes complete. */
+ we can lay it out later, when and if its type becomes complete.
+
+ Also handle constexpr pointer to member variables where the initializer
+ is an unlowered PTRMEM_CST because the class isn't complete yet. */
void
maybe_register_incomplete_var (tree var)
@@ -14034,6 +14045,15 @@ maybe_register_incomplete_var (tree var)
incomplete_var iv = {var, inner_type};
vec_safe_push (incomplete_vars, iv);
}
+ else if (TYPE_PTRMEM_P (inner_type)
+ && DECL_INITIAL (var)
+ && TREE_CODE (DECL_INITIAL (var)) == PTRMEM_CST)
+ {
+ tree context = TYPE_PTRMEM_CLASS_TYPE (inner_type);
+ gcc_assert (TYPE_BEING_DEFINED (context));
+ incomplete_var iv = {var, context};
+ vec_safe_push (incomplete_vars, iv);
+ }
}
}
@@ -14053,10 +14073,17 @@ complete_vars (tree type)
{
tree var = iv->decl;
tree type = TREE_TYPE (var);
- /* Complete the type of the variable. The VAR_DECL itself
- will be laid out in expand_expr. */
- complete_type (type);
- cp_apply_type_quals_to_decl (cp_type_quals (type), var);
+
+ if (TYPE_PTRMEM_P (type))
+ DECL_INITIAL (var) = cplus_expand_constant (DECL_INITIAL (var));
+ else
+ {
+ /* Complete the type of the variable. The VAR_DECL itself
+ will be laid out in expand_expr. */
+ complete_type (type);
+ cp_apply_type_quals_to_decl (cp_type_quals (type), var);
+ }
+
/* Remove this entry from the list. */
incomplete_vars->unordered_remove (ix);
}
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 82bc6f79e5b..f13efd67da9 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1121,7 +1121,7 @@ is_late_template_attribute (tree attr, tree decl)
second and following arguments. Attributes like mode, format,
cleanup and several target specific attributes aren't late
just because they have an IDENTIFIER_NODE as first argument. */
- if (arg == args && TREE_CODE (t) == IDENTIFIER_NODE)
+ if (arg == args && identifier_p (t))
continue;
if (value_dependent_expression_p (t)
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index c2bf54dcb2c..bcb0274c1b6 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -1783,6 +1783,8 @@ resolve_virtual_fun_from_obj_type_ref (tree ref)
static void
dump_expr (tree t, int flags)
{
+ tree op;
+
if (t == 0)
return;
@@ -2316,14 +2318,20 @@ dump_expr (tree t, int flags)
gcc_assert (TREE_CODE (t) == ALIGNOF_EXPR);
pp_cxx_ws_string (cxx_pp, "__alignof__");
}
+ op = TREE_OPERAND (t, 0);
+ if (PACK_EXPANSION_P (op))
+ {
+ pp_string (cxx_pp, "...");
+ op = PACK_EXPANSION_PATTERN (op);
+ }
pp_cxx_whitespace (cxx_pp);
pp_cxx_left_paren (cxx_pp);
if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t))
- dump_type (TREE_TYPE (TREE_OPERAND (t, 0)), flags);
+ dump_type (TREE_TYPE (op), flags);
else if (TYPE_P (TREE_OPERAND (t, 0)))
- dump_type (TREE_OPERAND (t, 0), flags);
+ dump_type (op, flags);
else
- dump_expr (TREE_OPERAND (t, 0), flags);
+ dump_expr (op, flags);
pp_cxx_right_paren (cxx_pp);
break;
@@ -3275,8 +3283,8 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec,
case 'D':
{
tree temp = next_tree;
- if (DECL_P (temp)
- && DECL_DEBUG_EXPR_IS_FROM (temp) && DECL_DEBUG_EXPR (temp))
+ if (TREE_CODE (temp) == VAR_DECL
+ && DECL_HAS_DEBUG_EXPR_P (temp))
{
temp = DECL_DEBUG_EXPR (temp);
if (!DECL_P (temp))
diff --git a/gcc/cp/except.c b/gcc/cp/except.c
index 216ec103f52..52ba1cdeae5 100644
--- a/gcc/cp/except.c
+++ b/gcc/cp/except.c
@@ -972,16 +972,8 @@ is_admissible_throw_operand_or_catch_parameter (tree t, bool is_throw)
/* 10.4/3 An abstract class shall not be used as a parameter type,
as a function return type or as type of an explicit
conversion. */
- else if (ABSTRACT_CLASS_TYPE_P (type))
- {
- if (is_throw)
- error ("expression %qE of abstract class type %qT cannot "
- "be used in throw-expression", expr, type);
- else
- error ("cannot declare catch parameter to be of abstract "
- "class type %qT", type);
- return false;
- }
+ else if (abstract_virtuals_error (is_throw ? ACU_THROW : ACU_CATCH, type))
+ return false;
else if (!is_throw
&& TREE_CODE (type) == REFERENCE_TYPE
&& TYPE_REF_IS_RVALUE (type))
diff --git a/gcc/cp/expr.c b/gcc/cp/expr.c
index ffd18ca6785..f15b049baf8 100644
--- a/gcc/cp/expr.c
+++ b/gcc/cp/expr.c
@@ -43,6 +43,10 @@ cplus_expand_constant (tree cst)
/* Find the member. */
member = PTRMEM_CST_MEMBER (cst);
+ /* We can't lower this until the class is complete. */
+ if (!COMPLETE_TYPE_P (DECL_CONTEXT (member)))
+ return cst;
+
if (TREE_CODE (member) == FIELD_DECL)
{
/* Find the offset for the field. */
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 697f11ff52e..32f242c3275 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -1416,7 +1416,7 @@ expand_member_init (tree name)
}
else
{
- if (TREE_CODE (name) == IDENTIFIER_NODE)
+ if (identifier_p (name))
field = lookup_field (current_class_type, name, 1, false);
else
field = name;
@@ -2301,7 +2301,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
return error_mark_node;
}
- if (abstract_virtuals_error_sfinae (NULL_TREE, elt_type, complain))
+ if (abstract_virtuals_error_sfinae (ACU_NEW, elt_type, complain))
return error_mark_node;
is_initialized = (type_build_ctor_call (elt_type) || *init != NULL);
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index a48d476856c..603f7019a70 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -1189,7 +1189,7 @@ write_unqualified_name (const tree decl)
{
MANGLE_TRACE_TREE ("unqualified-name", decl);
- if (TREE_CODE (decl) == IDENTIFIER_NODE)
+ if (identifier_p (decl))
{
write_unqualified_id (decl);
return;
@@ -2519,7 +2519,7 @@ write_template_args (tree args)
static void
write_member_name (tree member)
{
- if (TREE_CODE (member) == IDENTIFIER_NODE)
+ if (identifier_p (member))
write_unqualified_id (member);
else if (DECL_P (member))
write_unqualified_name (member);
@@ -2697,7 +2697,7 @@ write_expression (tree expr)
{
write_expression (TREE_OPERAND (expr, 0));
}
- else if (TREE_CODE (expr) == IDENTIFIER_NODE)
+ else if (identifier_p (expr))
{
/* An operator name appearing as a dependent name needs to be
specially marked to disambiguate between a use of the operator
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index ff29b596892..316c5d3b8eb 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -755,7 +755,7 @@ synthesize_method (tree fndecl)
tree stmt;
location_t save_input_location = input_location;
int error_count = errorcount;
- int warning_count = warningcount;
+ int warning_count = warningcount + werrorcount;
/* Reset the source location, we might have been previously
deferred, and thus have saved where we were first needed. */
@@ -817,7 +817,7 @@ synthesize_method (tree fndecl)
pop_deferring_access_checks ();
- if (error_count != errorcount || warning_count != warningcount)
+ if (error_count != errorcount || warning_count != warningcount + werrorcount)
inform (input_location, "synthesized method %qD first required here ",
fndecl);
}
@@ -1115,6 +1115,19 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
"initialize %q+#D", field);
}
}
+ else if (sfk == sfk_copy_constructor)
+ {
+ /* 12.8p11b5 */
+ if (TREE_CODE (mem_type) == REFERENCE_TYPE
+ && TYPE_REF_IS_RVALUE (mem_type))
+ {
+ if (diag)
+ error ("copying non-static data member %q#D of rvalue "
+ "reference type", field);
+ if (deleted_p)
+ *deleted_p = true;
+ }
+ }
if (!CLASS_TYPE_P (mem_type))
continue;
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 2a47331ea73..dd6ef223def 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -69,14 +69,12 @@ get_anonymous_namespace_name (void)
{
if (!anonymous_namespace_name)
{
- /* The anonymous namespace has to have a unique name
- if typeinfo objects are being compared by name. */
- if (! flag_weak || ! SUPPORTS_ONE_ONLY)
- anonymous_namespace_name = get_file_function_name ("N");
- else
- /* The demangler expects anonymous namespaces to be called
- something starting with '_GLOBAL__N_'. */
- anonymous_namespace_name = get_identifier ("_GLOBAL__N_1");
+ /* We used to use get_file_function_name here, but that isn't
+ necessary now that anonymous namespace typeinfos
+ are !TREE_PUBLIC, and thus compared by address. */
+ /* The demangler expects anonymous namespaces to be called
+ something starting with '_GLOBAL__N_'. */
+ anonymous_namespace_name = get_identifier ("_GLOBAL__N_1");
}
return anonymous_namespace_name;
}
@@ -1961,7 +1959,7 @@ constructor_name_p (tree name, tree type)
if (!name)
return false;
- if (TREE_CODE (name) != IDENTIFIER_NODE)
+ if (!identifier_p (name))
return false;
/* These don't have names. */
@@ -2075,7 +2073,7 @@ lookup_extern_c_fun_in_all_ns (tree function)
gcc_assert (function && TREE_CODE (function) == FUNCTION_DECL);
name = DECL_NAME (function);
- gcc_assert (name && TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (name && identifier_p (name));
for (iter = IDENTIFIER_NAMESPACE_BINDINGS (name);
iter;
@@ -2138,7 +2136,7 @@ push_using_decl_1 (tree scope, tree name)
tree decl;
gcc_assert (TREE_CODE (scope) == NAMESPACE_DECL);
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (name));
for (decl = current_binding_level->usings; decl; decl = DECL_CHAIN (decl))
if (USING_DECL_SCOPE (decl) == scope && DECL_NAME (decl) == name)
break;
@@ -5726,7 +5724,7 @@ pushtag_1 (tree name, tree type, tag_scope scope)
|| COMPLETE_TYPE_P (b->this_entity))))
b = b->level_chain;
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (name));
/* Do C++ gratuitous typedefing. */
if (identifier_type_value_1 (name) != type)
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index f9a0fbe4dcb..b88ada37c96 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -132,10 +132,11 @@ typedef enum tag_scope {
ts_global = 1, /* All scopes. This is the 3.4.1
[basic.lookup.unqual] lookup mentioned
in [basic.lookup.elab]/2. */
- ts_within_enclosing_non_class = 2 /* Search within enclosing non-class
+ ts_within_enclosing_non_class = 2, /* Search within enclosing non-class
only, for friend class lookup
according to [namespace.memdef]/3
and [class.friend]/9. */
+ ts_lambda = 3 /* Declaring a lambda closure. */
} tag_scope;
typedef struct GTY(()) cp_class_binding {
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ff4faa32d3c..7ac90df1671 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -1110,7 +1110,7 @@ cp_lexer_print_token (FILE * stream, cp_token *token)
case CPP_KEYWORD:
/* Some keywords have a value that is not an IDENTIFIER_NODE.
For example, `struct' is mapped to an INTEGER_CST. */
- if (TREE_CODE (token->u.value) != IDENTIFIER_NODE)
+ if (!identifier_p (token->u.value))
break;
/* else fall through */
case CPP_NAME:
@@ -1259,7 +1259,7 @@ make_id_declarator (tree qualifying_scope, tree unqualified_name,
if (qualifying_scope && TYPE_P (qualifying_scope))
qualifying_scope = TYPE_MAIN_VARIANT (qualifying_scope);
- gcc_assert (TREE_CODE (unqualified_name) == IDENTIFIER_NODE
+ gcc_assert (identifier_p (unqualified_name)
|| TREE_CODE (unqualified_name) == BIT_NOT_EXPR
|| TREE_CODE (unqualified_name) == TEMPLATE_ID_EXPR);
@@ -1802,7 +1802,7 @@ static tree cp_parser_nested_name_specifier
static tree cp_parser_qualifying_entity
(cp_parser *, bool, bool, bool, bool, bool);
static tree cp_parser_postfix_expression
- (cp_parser *, bool, bool, bool, cp_id_kind *);
+ (cp_parser *, bool, bool, bool, bool, cp_id_kind *);
static tree cp_parser_postfix_open_square_expression
(cp_parser *, tree, bool);
static tree cp_parser_postfix_dot_deref_expression
@@ -1832,7 +1832,7 @@ static vec<tree, va_gc> *cp_parser_new_initializer
static tree cp_parser_delete_expression
(cp_parser *);
static tree cp_parser_cast_expression
- (cp_parser *, bool, bool, cp_id_kind *);
+ (cp_parser *, bool, bool, bool, cp_id_kind *);
static tree cp_parser_binary_expression
(cp_parser *, bool, bool, enum cp_parser_prec, cp_id_kind *);
static tree cp_parser_question_colon_clause
@@ -1843,6 +1843,8 @@ static enum tree_code cp_parser_assignment_operator_opt
(cp_parser *);
static tree cp_parser_expression
(cp_parser *, bool, cp_id_kind *);
+static tree cp_parser_expression
+ (cp_parser *, bool, bool, cp_id_kind *);
static tree cp_parser_constant_expression
(cp_parser *, bool, bool *);
static tree cp_parser_builtin_offsetof
@@ -2585,7 +2587,7 @@ cp_parser_check_for_invalid_template_id (cp_parser* parser,
{
if (TYPE_P (type))
error_at (location, "%qT is not a template", type);
- else if (TREE_CODE (type) == IDENTIFIER_NODE)
+ else if (identifier_p (type))
{
if (tag_type != none_type)
error_at (location, "%qE is not a class template", type);
@@ -3191,7 +3193,7 @@ cp_parser_make_typename_type (cp_parser *parser, tree scope,
tree id, location_t id_location)
{
tree result;
- if (TREE_CODE (id) == IDENTIFIER_NODE)
+ if (identifier_p (id))
{
result = make_typename_type (scope, id, typename_type,
/*complain=*/tf_none);
@@ -3559,21 +3561,20 @@ lookup_literal_operator (tree name, vec<tree, va_gc> *args)
unsigned int ix;
bool found = true;
tree fn = OVL_CURRENT (fns);
- tree argtypes = NULL_TREE;
- argtypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
- if (argtypes != NULL_TREE)
+ tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
+ if (parmtypes != NULL_TREE)
{
- for (ix = 0; ix < vec_safe_length (args) && argtypes != NULL_TREE;
- ++ix, argtypes = TREE_CHAIN (argtypes))
+ for (ix = 0; ix < vec_safe_length (args) && parmtypes != NULL_TREE;
+ ++ix, parmtypes = TREE_CHAIN (parmtypes))
{
- tree targ = TREE_VALUE (argtypes);
- tree tparm = TREE_TYPE ((*args)[ix]);
- bool ptr = TREE_CODE (targ) == POINTER_TYPE;
- bool arr = TREE_CODE (tparm) == ARRAY_TYPE;
- if ((ptr || arr || !same_type_p (targ, tparm))
+ tree tparm = TREE_VALUE (parmtypes);
+ tree targ = TREE_TYPE ((*args)[ix]);
+ bool ptr = TREE_CODE (tparm) == POINTER_TYPE;
+ bool arr = TREE_CODE (targ) == ARRAY_TYPE;
+ if ((ptr || arr || !same_type_p (tparm, targ))
&& (!ptr || !arr
- || !same_type_p (TREE_TYPE (targ),
- TREE_TYPE (tparm))))
+ || !same_type_p (TREE_TYPE (tparm),
+ TREE_TYPE (targ))))
found = false;
}
if (found
@@ -3582,7 +3583,7 @@ lookup_literal_operator (tree name, vec<tree, va_gc> *args)
depending on how exactly should user-defined literals
work in presence of default arguments on the literal
operator parameters. */
- && argtypes == void_list_node)
+ && parmtypes == void_list_node)
return fn;
}
}
@@ -3901,6 +3902,7 @@ cp_parser_primary_expression (cp_parser *parser,
bool address_p,
bool cast_p,
bool template_arg_p,
+ bool decltype_p,
cp_id_kind *idk)
{
cp_token *token = NULL;
@@ -4052,7 +4054,7 @@ cp_parser_primary_expression (cp_parser *parser,
else
{
/* Parse the parenthesized expression. */
- expr = cp_parser_expression (parser, cast_p, idk);
+ expr = cp_parser_expression (parser, cast_p, decltype_p, idk);
/* Let the front end know that this expression was
enclosed in parentheses. This matters in case, for
example, the expression is of the form `A::B', since
@@ -4404,6 +4406,17 @@ cp_parser_primary_expression (cp_parser *parser,
}
}
+static inline tree
+cp_parser_primary_expression (cp_parser *parser,
+ bool address_p,
+ bool cast_p,
+ bool template_arg_p,
+ cp_id_kind *idk)
+{
+ return cp_parser_primary_expression (parser, address_p, cast_p, template_arg_p,
+ /*decltype*/false, idk);
+}
+
/* Parse an id-expression.
id-expression:
@@ -5365,7 +5378,7 @@ cp_parser_qualifying_entity (cp_parser *parser,
static tree
cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
- bool member_access_only_p,
+ bool member_access_only_p, bool decltype_p,
cp_id_kind * pidk_return)
{
cp_token *token;
@@ -5626,16 +5639,22 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
postfix_expression
= cp_parser_primary_expression (parser, address_p, cast_p,
/*template_arg_p=*/false,
+ decltype_p,
&idk);
}
break;
}
+ /* Note that we don't need to worry about calling build_cplus_new on a
+ class-valued CALL_EXPR in decltype when it isn't the end of the
+ postfix-expression; unary_complex_lvalue will take care of that for
+ all these cases. */
+
/* Keep looping until the postfix-expression is complete. */
while (true)
{
if (idk == CP_ID_KIND_UNQUALIFIED
- && TREE_CODE (postfix_expression) == IDENTIFIER_NODE
+ && identifier_p (postfix_expression)
&& cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN))
/* It is not a Koenig lookup function call. */
postfix_expression
@@ -5669,8 +5688,12 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
bool is_builtin_constant_p;
bool saved_integral_constant_expression_p = false;
bool saved_non_integral_constant_expression_p = false;
+ int complain = tf_warning_or_error;
vec<tree, va_gc> *args;
+ if (decltype_p)
+ complain |= tf_decltype;
+
is_member_access = false;
is_builtin_constant_p
@@ -5718,7 +5741,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
if (idk == CP_ID_KIND_UNQUALIFIED
|| idk == CP_ID_KIND_TEMPLATE_ID)
{
- if (TREE_CODE (postfix_expression) == IDENTIFIER_NODE)
+ if (identifier_p (postfix_expression))
{
if (!args->is_empty ())
{
@@ -5727,7 +5750,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
postfix_expression
= perform_koenig_lookup (postfix_expression, args,
/*include_std=*/false,
- tf_warning_or_error);
+ complain);
}
else
postfix_expression
@@ -5753,7 +5776,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
postfix_expression
= perform_koenig_lookup (postfix_expression, args,
/*include_std=*/false,
- tf_warning_or_error);
+ complain);
}
}
}
@@ -5785,21 +5808,21 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
: LOOKUP_NORMAL),
/*fn_p=*/NULL,
- tf_warning_or_error));
+ complain));
}
else
postfix_expression
= finish_call_expr (postfix_expression, &args,
/*disallow_virtual=*/false,
/*koenig_p=*/false,
- tf_warning_or_error);
+ complain);
}
else if (TREE_CODE (postfix_expression) == OFFSET_REF
|| TREE_CODE (postfix_expression) == MEMBER_REF
|| TREE_CODE (postfix_expression) == DOTSTAR_EXPR)
postfix_expression = (build_offset_ref_call_from_tree
(postfix_expression, &args,
- tf_warning_or_error));
+ complain));
else if (idk == CP_ID_KIND_QUALIFIED)
/* A call to a static class member, or a namespace-scope
function. */
@@ -5807,14 +5830,14 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
= finish_call_expr (postfix_expression, &args,
/*disallow_virtual=*/true,
koenig_p,
- tf_warning_or_error);
+ complain);
else
/* All other function calls. */
postfix_expression
= finish_call_expr (postfix_expression, &args,
/*disallow_virtual=*/false,
koenig_p,
- tf_warning_or_error);
+ complain);
/* The POSTFIX_EXPRESSION is certainly no longer an id. */
idk = CP_ID_KIND_NONE;
@@ -6415,7 +6438,7 @@ cp_parser_pseudo_destructor_name (cp_parser* parser,
static tree
cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p,
- cp_id_kind * pidk)
+ bool decltype_p, cp_id_kind * pidk)
{
cp_token *token;
enum tree_code unary_operator;
@@ -6636,7 +6659,9 @@ cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p,
cast_expression
= cp_parser_cast_expression (parser,
unary_operator == ADDR_EXPR,
- /*cast_p=*/false, pidk);
+ /*cast_p=*/false,
+ /*decltype*/false,
+ pidk);
/* Now, build an appropriate representation. */
switch (unary_operator)
{
@@ -6682,9 +6707,18 @@ cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p,
return cp_parser_postfix_expression (parser, address_p, cast_p,
/*member_access_only_p=*/false,
+ decltype_p,
pidk);
}
+static inline tree
+cp_parser_unary_expression (cp_parser *parser, bool address_p, bool cast_p,
+ cp_id_kind * pidk)
+{
+ return cp_parser_unary_expression (parser, address_p, cast_p,
+ /*decltype*/false, pidk);
+}
+
/* Returns ERROR_MARK if TOKEN is not a unary-operator. If TOKEN is a
unary-operator, the corresponding tree code is returned. */
@@ -7163,7 +7197,7 @@ cp_parser_tokens_start_cast_expression (cp_parser *parser)
static tree
cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p,
- cp_id_kind * pidk)
+ bool decltype_p, cp_id_kind * pidk)
{
/* If it's a `(', then we might be looking at a cast. */
if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
@@ -7237,7 +7271,9 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p,
cp_parser_parse_definitely (parser);
expr = cp_parser_cast_expression (parser,
/*address_p=*/false,
- /*cast_p=*/true, pidk);
+ /*cast_p=*/true,
+ /*decltype_p=*/false,
+ pidk);
/* Warn about old-style casts, if so requested. */
if (warn_old_style_cast
@@ -7263,7 +7299,8 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p,
/* If we get here, then it's not a cast, so it must be a
unary-expression. */
- return cp_parser_unary_expression (parser, address_p, cast_p, pidk);
+ return cp_parser_unary_expression (parser, address_p, cast_p,
+ decltype_p, pidk);
}
/* Parse a binary expression of the general form:
@@ -7348,6 +7385,7 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p,
static tree
cp_parser_binary_expression (cp_parser* parser, bool cast_p,
bool no_toplevel_fold_p,
+ bool decltype_p,
enum cp_parser_prec prec,
cp_id_kind * pidk)
{
@@ -7362,7 +7400,7 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
/* Parse the first expression. */
current.lhs = cp_parser_cast_expression (parser, /*address_p=*/false,
- cast_p, pidk);
+ cast_p, decltype_p, pidk);
current.lhs_type = ERROR_MARK;
current.prec = prec;
@@ -7499,6 +7537,15 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
return current.lhs;
}
+static tree
+cp_parser_binary_expression (cp_parser* parser, bool cast_p,
+ bool no_toplevel_fold_p,
+ enum cp_parser_prec prec,
+ cp_id_kind * pidk)
+{
+ return cp_parser_binary_expression (parser, cast_p, no_toplevel_fold_p,
+ /*decltype*/false, prec, pidk);
+}
/* Parse the `? expression : assignment-expression' part of a
conditional-expression. The LOGICAL_OR_EXPR is the
@@ -7568,12 +7615,13 @@ cp_parser_question_colon_clause (cp_parser* parser, tree logical_or_expr)
throw-expression
CAST_P is true if this expression is the target of a cast.
+ DECLTYPE_P is true if this expression is the operand of decltype.
Returns a representation for the expression. */
static tree
cp_parser_assignment_expression (cp_parser* parser, bool cast_p,
- cp_id_kind * pidk)
+ bool decltype_p, cp_id_kind * pidk)
{
tree expr;
@@ -7587,6 +7635,7 @@ cp_parser_assignment_expression (cp_parser* parser, bool cast_p,
{
/* Parse the binary expressions (logical-or-expression). */
expr = cp_parser_binary_expression (parser, cast_p, false,
+ decltype_p,
PREC_NOT_OPERATOR, pidk);
/* If the next token is a `?' then we're actually looking at a
conditional-expression. */
@@ -7632,6 +7681,14 @@ cp_parser_assignment_expression (cp_parser* parser, bool cast_p,
return expr;
}
+static tree
+cp_parser_assignment_expression (cp_parser* parser, bool cast_p,
+ cp_id_kind * pidk)
+{
+ return cp_parser_assignment_expression (parser, cast_p,
+ /*decltype*/false, pidk);
+}
+
/* Parse an (optional) assignment-operator.
assignment-operator: one of
@@ -7723,11 +7780,14 @@ cp_parser_assignment_operator_opt (cp_parser* parser)
expression , assignment-expression
CAST_P is true if this expression is the target of a cast.
+ DECLTYPE_P is true if this expression is the immediate operand of decltype,
+ except possibly parenthesized or on the RHS of a comma (N3276).
Returns a representation of the expression. */
static tree
-cp_parser_expression (cp_parser* parser, bool cast_p, cp_id_kind * pidk)
+cp_parser_expression (cp_parser* parser, bool cast_p, bool decltype_p,
+ cp_id_kind * pidk)
{
tree expression = NULL_TREE;
location_t loc = UNKNOWN_LOCATION;
@@ -7738,7 +7798,19 @@ cp_parser_expression (cp_parser* parser, bool cast_p, cp_id_kind * pidk)
/* Parse the next assignment-expression. */
assignment_expression
- = cp_parser_assignment_expression (parser, cast_p, pidk);
+ = cp_parser_assignment_expression (parser, cast_p, decltype_p, pidk);
+
+ /* We don't create a temporary for a call that is the immediate operand
+ of decltype or on the RHS of a comma. But when we see a comma, we
+ need to create a temporary for a call on the LHS. */
+ if (decltype_p && !processing_template_decl
+ && TREE_CODE (assignment_expression) == CALL_EXPR
+ && CLASS_TYPE_P (TREE_TYPE (assignment_expression))
+ && cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+ assignment_expression
+ = build_cplus_new (TREE_TYPE (assignment_expression),
+ assignment_expression, tf_warning_or_error);
+
/* If this is the first assignment-expression, we can just
save it away. */
if (!expression)
@@ -7762,6 +7834,12 @@ cp_parser_expression (cp_parser* parser, bool cast_p, cp_id_kind * pidk)
return expression;
}
+static inline tree
+cp_parser_expression (cp_parser* parser, bool cast_p, cp_id_kind * pidk)
+{
+ return cp_parser_expression (parser, cast_p, /*decltype*/false, pidk);
+}
+
/* Parse a constant-expression.
constant-expression:
@@ -8196,19 +8274,8 @@ cp_parser_lambda_expression (cp_parser* parser)
cp_parser_skip_to_end_of_block_or_statement (parser);
/* The capture list was built up in reverse order; fix that now. */
- {
- tree newlist = NULL_TREE;
- tree elt, next;
-
- for (elt = LAMBDA_EXPR_CAPTURE_LIST (lambda_expr);
- elt; elt = next)
- {
- next = TREE_CHAIN (elt);
- TREE_CHAIN (elt) = newlist;
- newlist = elt;
- }
- LAMBDA_EXPR_CAPTURE_LIST (lambda_expr) = newlist;
- }
+ LAMBDA_EXPR_CAPTURE_LIST (lambda_expr)
+ = nreverse (LAMBDA_EXPR_CAPTURE_LIST (lambda_expr));
if (ok)
maybe_add_lambda_conv_op (type);
@@ -8487,7 +8554,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
if (cp_lexer_next_token_is (parser->lexer, CPP_DEREF))
{
cp_lexer_consume_token (parser->lexer);
- LAMBDA_EXPR_RETURN_TYPE (lambda_expr) = cp_parser_type_id (parser);
+ LAMBDA_EXPR_RETURN_TYPE (lambda_expr)
+ = cp_parser_trailing_type_id (parser);
}
/* The function parameters must be in scope all the way until after the
@@ -11242,7 +11310,7 @@ cp_parser_decltype (cp_parser *parser)
cp_id_kind idk;
const char *error_msg;
- if (TREE_CODE (expr) == IDENTIFIER_NODE)
+ if (identifier_p (expr))
/* Lookup the name we got back from the id-expression. */
expr = cp_parser_lookup_name (parser, expr,
none_type,
@@ -11299,7 +11367,7 @@ cp_parser_decltype (cp_parser *parser)
/* Parse a class member access. */
expr = cp_parser_postfix_expression (parser, /*address_p=*/false,
- /*cast_p=*/false,
+ /*cast_p=*/false, /*decltype*/true,
/*member_access_only_p=*/true, NULL);
if (expr
@@ -11327,7 +11395,8 @@ cp_parser_decltype (cp_parser *parser)
parser->greater_than_is_operator_p = true;
/* Parse a full expression. */
- expr = cp_parser_expression (parser, /*cast_p=*/false, NULL);
+ expr = cp_parser_expression (parser, /*cast_p=*/false,
+ /*decltype*/true, NULL);
/* The `>' token might be the end of a template-id or
template-parameter-list now. */
@@ -12690,7 +12759,7 @@ cp_parser_template_id (cp_parser *parser,
}
/* Build a representation of the specialization. */
- if (TREE_CODE (templ) == IDENTIFIER_NODE)
+ if (identifier_p (templ))
template_id = build_min_nt_loc (next_token->location,
TEMPLATE_ID_EXPR,
templ, arguments);
@@ -12750,7 +12819,7 @@ cp_parser_template_id (cp_parser *parser,
error_at (token->location, "parse error in template argument list");
}
- pop_deferring_access_checks ();
+ pop_to_parent_deferring_access_checks ();
return template_id;
}
@@ -13266,7 +13335,6 @@ cp_parser_template_argument (cp_parser* parser)
argument = cp_parser_constant_expression (parser,
/*allow_non_constant_p=*/false,
/*non_constant_p=*/NULL);
- argument = fold_non_dependent_expr (argument);
if (!maybe_type_id)
return argument;
if (!cp_parser_next_token_ends_template_argument_p (parser))
@@ -13912,7 +13980,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
&& !global_p
&& !qualified_p
&& TREE_CODE (type) == TYPE_DECL
- && TREE_CODE (DECL_NAME (type)) == IDENTIFIER_NODE)
+ && identifier_p (DECL_NAME (type)))
maybe_note_name_used_in_class (DECL_NAME (type), type);
/* If it didn't work out, we don't have a TYPE. */
if ((flags & CP_PARSER_FLAGS_OPTIONAL)
@@ -15211,7 +15279,7 @@ cp_parser_using_declaration (cp_parser* parser,
depending on what scope we are in. */
if (qscope == error_mark_node || identifier == error_mark_node)
;
- else if (TREE_CODE (identifier) != IDENTIFIER_NODE
+ else if (!identifier_p (identifier)
&& TREE_CODE (identifier) != BIT_NOT_EXPR)
/* [namespace.udecl]
@@ -16299,6 +16367,8 @@ cp_parser_direct_declarator (cp_parser* parser,
tree exception_specification;
tree late_return;
tree attrs;
+ bool memfn = (member_p || (pushed_scope
+ && CLASS_TYPE_P (pushed_scope)));
is_declarator = true;
@@ -16315,7 +16385,7 @@ cp_parser_direct_declarator (cp_parser* parser,
attrs = cp_parser_std_attribute_spec_seq (parser);
late_return = (cp_parser_late_return_type_opt
- (parser, member_p ? cv_quals : -1));
+ (parser, memfn ? cv_quals : -1));
/* Parse the virt-specifier-seq. */
virt_specifiers = cp_parser_virt_specifier_seq_opt (parser);
@@ -16492,8 +16562,7 @@ cp_parser_direct_declarator (cp_parser* parser,
unqualified_name = error_mark_node;
else if (unqualified_name
&& (qualifying_scope
- || (TREE_CODE (unqualified_name)
- != IDENTIFIER_NODE)))
+ || (!identifier_p (unqualified_name))))
{
cp_parser_error (parser, "expected unqualified-id");
unqualified_name = error_mark_node;
@@ -16637,9 +16706,18 @@ cp_parser_direct_declarator (cp_parser* parser,
handle_declarator:;
scope = get_scope_of_declarator (declarator);
if (scope)
- /* Any names that appear after the declarator-id for a
- member are looked up in the containing scope. */
- pushed_scope = push_scope (scope);
+ {
+ /* Any names that appear after the declarator-id for a
+ member are looked up in the containing scope. */
+ if (at_function_scope_p ())
+ {
+ /* But declarations with qualified-ids can't appear in a
+ function. */
+ cp_parser_error (parser, "qualified-id in declaration");
+ break;
+ }
+ pushed_scope = push_scope (scope);
+ }
parser->in_declarator_p = true;
if ((ctor_dtor_or_conv_p && *ctor_dtor_or_conv_p)
|| (declarator && declarator->kind == cdk_id))
@@ -16939,6 +17017,19 @@ inject_this_parameter (tree ctype, cp_cv_quals quals)
current_class_ptr = this_parm;
}
+/* Return true iff our current scope is a non-static data member
+ initializer. */
+
+bool
+parsing_nsdmi (void)
+{
+ /* We recognize NSDMI context by the context-less 'this' pointer set up
+ by the function above. */
+ if (current_class_ptr && DECL_CONTEXT (current_class_ptr) == NULL_TREE)
+ return true;
+ return false;
+}
+
/* Parse a late-specified return type, if any. This is not a separate
non-terminal, but part of a function declarator, which looks like
@@ -16964,17 +17055,21 @@ cp_parser_late_return_type_opt (cp_parser* parser, cp_cv_quals quals)
/* Consume the ->. */
cp_lexer_consume_token (parser->lexer);
+ tree save_ccp = current_class_ptr;
+ tree save_ccr = current_class_ref;
if (quals >= 0)
{
/* DR 1207: 'this' is in scope in the trailing return type. */
- gcc_assert (current_class_ptr == NULL_TREE);
inject_this_parameter (current_class_type, quals);
}
type = cp_parser_trailing_type_id (parser);
if (quals >= 0)
- current_class_ptr = current_class_ref = NULL_TREE;
+ {
+ current_class_ptr = save_ccp;
+ current_class_ref = save_ccr;
+ }
return type;
}
@@ -18130,7 +18225,7 @@ cp_parser_class_name (cp_parser *parser,
/* Check to see that it is really the name of a class. */
if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
- && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
+ && identifier_p (TREE_OPERAND (decl, 0))
&& cp_lexer_next_token_is (parser->lexer, CPP_SCOPE))
/* Situations like this:
@@ -21024,7 +21119,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
/* By this point, the NAME should be an ordinary identifier. If
the id-expression was a qualified name, the qualifying scope is
stored in PARSER->SCOPE at this point. */
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (name));
/* Perform the lookup. */
if (parser->scope)
@@ -22033,7 +22128,7 @@ static tree
cp_parser_simple_cast_expression (cp_parser *parser)
{
return cp_parser_cast_expression (parser, /*address_p=*/false,
- /*cast_p=*/false, NULL);
+ /*cast_p=*/false, /*decltype*/false, NULL);
}
/* Parse a functional cast to TYPE. Returns an expression
@@ -24194,7 +24289,7 @@ cp_parser_objc_protocol_qualifiers (cp_parser* parser)
node = token->u.value;
- while (node && TREE_CODE (node) == IDENTIFIER_NODE
+ while (node && identifier_p (node)
&& (node == ridpointers [(int) RID_IN]
|| node == ridpointers [(int) RID_OUT]
|| node == ridpointers [(int) RID_INOUT]
@@ -26830,7 +26925,7 @@ cp_parser_omp_for_incr (cp_parser *parser, tree decl)
op = (token->type == CPP_PLUS_PLUS
? PREINCREMENT_EXPR : PREDECREMENT_EXPR);
cp_lexer_consume_token (parser->lexer);
- lhs = cp_parser_cast_expression (parser, false, false, NULL);
+ lhs = cp_parser_simple_cast_expression (parser);
if (lhs != decl)
return error_mark_node;
return build2 (op, TREE_TYPE (decl), decl, NULL_TREE);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index eb9fc7f94c7..b6066c18bde 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -1009,6 +1009,9 @@ optimize_specialization_lookup_p (tree tmpl)
static tree
retrieve_specialization (tree tmpl, tree args, hashval_t hash)
{
+ if (tmpl == NULL_TREE)
+ return NULL_TREE;
+
if (args == error_mark_node)
return NULL_TREE;
@@ -2464,7 +2467,7 @@ check_explicit_specialization (tree declarator,
{
tree fns;
- gcc_assert (TREE_CODE (declarator) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (declarator));
if (ctype)
fns = dname;
else
@@ -2525,8 +2528,7 @@ check_explicit_specialization (tree declarator,
return decl;
}
else if (ctype != NULL_TREE
- && (TREE_CODE (TREE_OPERAND (declarator, 0)) ==
- IDENTIFIER_NODE))
+ && (identifier_p (TREE_OPERAND (declarator, 0))))
{
/* Find the list of functions in ctype that have the same
name as the declared function. */
@@ -4306,6 +4308,13 @@ check_default_tmpl_args (tree decl, tree parms, bool is_primary,
local scope. */
return true;
+ if (TREE_CODE (decl) == TYPE_DECL
+ && TREE_TYPE (decl)
+ && LAMBDA_TYPE_P (TREE_TYPE (decl)))
+ /* A lambda doesn't have an explicit declaration; don't complain
+ about the parms of the enclosing class. */
+ return true;
+
if (current_class_type
&& !TYPE_BEING_DEFINED (current_class_type)
&& DECL_LANG_SPECIFIC (decl)
@@ -4674,6 +4683,8 @@ push_template_decl_real (tree decl, bool is_friend)
if (!ctx
|| TREE_CODE (ctx) == FUNCTION_DECL
|| (CLASS_TYPE_P (ctx) && TYPE_BEING_DEFINED (ctx))
+ || (TREE_CODE (decl) == TYPE_DECL
+ && LAMBDA_TYPE_P (TREE_TYPE (decl)))
|| (is_friend && !DECL_TEMPLATE_INFO (decl)))
{
if (DECL_LANG_SPECIFIC (decl)
@@ -5044,9 +5055,8 @@ fold_non_dependent_expr_sfinae (tree expr, tsubst_flags_t complain)
as two declarations of the same function, for example. */
if (processing_template_decl
- && !type_dependent_expression_p (expr)
- && potential_constant_expression (expr)
- && !value_dependent_expression_p (expr))
+ && !instantiation_dependent_expression_p (expr)
+ && potential_constant_expression (expr))
{
HOST_WIDE_INT saved_processing_template_decl;
@@ -5554,15 +5564,19 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
qualification conversion. Let's strip everything. */
else if (TREE_CODE (expr) == NOP_EXPR && TYPE_PTROBV_P (type))
{
- STRIP_NOPS (expr);
- gcc_assert (TREE_CODE (expr) == ADDR_EXPR);
- gcc_assert (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE);
- /* Skip the ADDR_EXPR only if it is part of the decay for
- an array. Otherwise, it is part of the original argument
- in the source code. */
- if (TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == ARRAY_TYPE)
- expr = TREE_OPERAND (expr, 0);
- expr_type = TREE_TYPE (expr);
+ tree probe = expr;
+ STRIP_NOPS (probe);
+ if (TREE_CODE (probe) == ADDR_EXPR
+ && TREE_CODE (TREE_TYPE (probe)) == POINTER_TYPE)
+ {
+ /* Skip the ADDR_EXPR only if it is part of the decay for
+ an array. Otherwise, it is part of the original argument
+ in the source code. */
+ if (TREE_CODE (TREE_TYPE (TREE_OPERAND (probe, 0))) == ARRAY_TYPE)
+ probe = TREE_OPERAND (probe, 0);
+ expr = probe;
+ expr_type = TREE_TYPE (expr);
+ }
}
/* [temp.arg.nontype]/5, bullet 1
@@ -5586,12 +5600,12 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
{
if (complain & tf_error)
{
- int errs = errorcount, warns = warningcount;
+ int errs = errorcount, warns = warningcount + werrorcount;
if (processing_template_decl
&& !require_potential_constant_expression (expr))
return NULL_TREE;
expr = cxx_constant_value (expr);
- if (errorcount > errs || warningcount > warns)
+ if (errorcount > errs || warningcount + werrorcount > warns)
inform (EXPR_LOC_OR_HERE (expr),
"in template argument for type %qT ", type);
if (expr == error_mark_node)
@@ -5641,6 +5655,13 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
expr, expr);
return NULL_TREE;
}
+ if (POINTER_TYPE_P (expr_type))
+ {
+ error ("%qE is not a valid template argument for %qT"
+ "because it is not the address of a variable",
+ expr, type);
+ return NULL_TREE;
+ }
/* Other values, like integer constants, might be valid
non-type arguments of some other type. */
return error_mark_node;
@@ -5788,7 +5809,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
return NULL_TREE;
}
- expr = convert_nontype_argument_function (TREE_TYPE (type), expr);
+ expr = convert_nontype_argument_function (type, expr);
if (!expr || expr == error_mark_node)
return expr;
@@ -6933,7 +6954,7 @@ lookup_template_function (tree fns, tree arglist)
gcc_assert (!arglist || TREE_CODE (arglist) == TREE_VEC);
- if (!is_overloaded_fn (fns) && TREE_CODE (fns) != IDENTIFIER_NODE)
+ if (!is_overloaded_fn (fns) && !identifier_p (fns))
{
error ("%q#D is not a function template", fns);
return error_mark_node;
@@ -7036,7 +7057,7 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
spec_entry elt;
hashval_t hash;
- if (TREE_CODE (d1) == IDENTIFIER_NODE)
+ if (identifier_p (d1))
{
tree value = innermost_non_namespace_value (d1);
if (value && DECL_TEMPLATE_TEMPLATE_PARM_P (value))
@@ -7831,7 +7852,7 @@ uses_template_parms (tree t)
|| TREE_CODE (t) == TEMPLATE_PARM_INDEX
|| TREE_CODE (t) == OVERLOAD
|| BASELINK_P (t)
- || TREE_CODE (t) == IDENTIFIER_NODE
+ || identifier_p (t)
|| TREE_CODE (t) == TRAIT_EXPR
|| TREE_CODE (t) == CONSTRUCTOR
|| CONSTANT_CLASS_P (t))
@@ -8460,8 +8481,7 @@ apply_late_template_attributes (tree *decl_p, tree attributes, int attr_flags,
if (TREE_VALUE (t)
&& TREE_CODE (TREE_VALUE (t)) == TREE_LIST
&& TREE_VALUE (TREE_VALUE (t))
- && (TREE_CODE (TREE_VALUE (TREE_VALUE (t)))
- == IDENTIFIER_NODE))
+ && (identifier_p (TREE_VALUE (TREE_VALUE (t)))))
{
tree chain
= tsubst_expr (TREE_CHAIN (TREE_VALUE (t)), args, complain,
@@ -8992,12 +9012,26 @@ instantiate_class_template_1 (tree type)
}
}
- if (CLASSTYPE_LAMBDA_EXPR (type))
+ if (tree expr = CLASSTYPE_LAMBDA_EXPR (type))
{
tree decl = lambda_function (type);
if (decl)
{
instantiate_decl (decl, false, false);
+
+ /* We need to instantiate the capture list from the template
+ after we've instantiated the closure members, but before we
+ consider adding the conversion op. Also keep any captures
+ that may have been added during instantiation of the op(). */
+ tree tmpl_expr = CLASSTYPE_LAMBDA_EXPR (pattern);
+ tree tmpl_cap
+ = tsubst_copy_and_build (LAMBDA_EXPR_CAPTURE_LIST (tmpl_expr),
+ args, tf_warning_or_error, NULL_TREE,
+ false, false);
+
+ LAMBDA_EXPR_CAPTURE_LIST (expr)
+ = chainon (tmpl_cap, nreverse (LAMBDA_EXPR_CAPTURE_LIST (expr)));
+
maybe_add_lambda_conv_op (type);
}
else
@@ -10252,7 +10286,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
DECL_TEMPLATE_INFO (r)
= build_template_info (gen_tmpl, argvec);
SET_DECL_IMPLICIT_INSTANTIATION (r);
- register_specialization (r, gen_tmpl, argvec, false, hash);
+
+ tree new_r
+ = register_specialization (r, gen_tmpl, argvec, false, hash);
+ if (new_r != r)
+ /* We instantiated this while substituting into
+ the type earlier (template/friend54.C). */
+ RETURN (new_r);
/* We're not supposed to instantiate default arguments
until they are called, for a template. But, for a
@@ -10826,6 +10866,9 @@ tsubst_arg_types (tree arg_types,
}
return error_mark_node;
}
+ /* DR 657. */
+ if (abstract_virtuals_error_sfinae (ACU_PARM, type, complain))
+ return error_mark_node;
/* Do array-to-pointer, function-to-pointer conversion, and ignore
top-level qualifiers as required. */
@@ -10888,10 +10931,8 @@ tsubst_function_type (tree t,
return_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
if (return_type == error_mark_node)
return error_mark_node;
- /* The standard does not presently indicate that creation of a
- function type with an invalid return type is a deduction failure.
- However, that is clearly analogous to creating an array of "void"
- or a reference to a reference. This is core issue #486. */
+ /* DR 486 clarifies that creation of a function type with an
+ invalid return type is a deduction failure. */
if (TREE_CODE (return_type) == ARRAY_TYPE
|| TREE_CODE (return_type) == FUNCTION_TYPE)
{
@@ -10904,6 +10945,9 @@ tsubst_function_type (tree t,
}
return error_mark_node;
}
+ /* And DR 657. */
+ if (abstract_virtuals_error_sfinae (ACU_RETURN, return_type, complain))
+ return error_mark_node;
/* Substitute the argument types. */
arg_types = tsubst_arg_types (TYPE_ARG_TYPES (t), args, NULL_TREE,
@@ -11625,13 +11669,9 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
error ("creating array of %qT", type);
return error_mark_node;
}
- if (ABSTRACT_CLASS_TYPE_P (type))
- {
- if (complain & tf_error)
- error ("creating array of %qT, which is an abstract class type",
- type);
- return error_mark_node;
- }
+
+ if (abstract_virtuals_error_sfinae (ACU_ARRAY, type, complain))
+ return error_mark_node;
r = build_cplus_array_type (type, domain);
@@ -11757,7 +11797,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
++c_inhibit_evaluation_warnings;
type = tsubst_expr (DECLTYPE_TYPE_EXPR (t), args,
- complain, in_decl,
+ complain|tf_decltype, in_decl,
/*integral_constant_expression_p=*/false);
--cp_unevaluated_operand;
@@ -12010,7 +12050,7 @@ tsubst_qualified_id (tree qualified_id, tree args,
else if (TYPE_P (scope))
{
expr = (adjust_result_of_qualified_name_lookup
- (expr, scope, current_class_type));
+ (expr, scope, current_nonlambda_class_type ()));
expr = (finish_qualified_id_expr
(scope, expr, done, address_p && PTRMEM_OK_P (qualified_id),
QUALIFIED_NAME_IS_TEMPLATE (qualified_id),
@@ -13393,6 +13433,12 @@ tsubst_copy_and_build (tree t,
if (EXPR_HAS_LOCATION (t))
input_location = EXPR_LOCATION (t);
+ /* N3276 decltype magic only applies to calls at the top level or on the
+ right side of a comma. */
+ if (TREE_CODE (t) != CALL_EXPR
+ && TREE_CODE (t) != COMPOUND_EXPR)
+ complain &= ~tf_decltype;
+
switch (TREE_CODE (t))
{
case USING_DECL:
@@ -13432,7 +13478,7 @@ tsubst_copy_and_build (tree t,
input_location);
if (error_msg)
error (error_msg);
- if (!function_p && TREE_CODE (decl) == IDENTIFIER_NODE)
+ if (!function_p && identifier_p (decl))
{
if (complain & tf_error)
unqualified_name_lookup_error (decl);
@@ -13824,10 +13870,16 @@ tsubst_copy_and_build (tree t,
complain));
case COMPOUND_EXPR:
- RETURN (build_x_compound_expr (EXPR_LOCATION (t),
- RECUR (TREE_OPERAND (t, 0)),
- RECUR (TREE_OPERAND (t, 1)),
- complain));
+ {
+ tree op0 = tsubst_copy_and_build (TREE_OPERAND (t, 0), args,
+ complain & ~tf_decltype, in_decl,
+ /*function_p=*/false,
+ integral_constant_expression_p);
+ RETURN (build_x_compound_expr (EXPR_LOCATION (t),
+ op0,
+ RECUR (TREE_OPERAND (t, 1)),
+ complain));
+ }
case CALL_EXPR:
{
@@ -13838,6 +13890,10 @@ tsubst_copy_and_build (tree t,
bool koenig_p;
tree ret;
+ /* Don't pass tf_decltype down to subexpressions. */
+ tsubst_flags_t decltype_flag = (complain & tf_decltype);
+ complain &= ~tf_decltype;
+
function = CALL_EXPR_FN (t);
/* When we parsed the expression, we determined whether or
not Koenig lookup should be performed. */
@@ -13849,7 +13905,7 @@ tsubst_copy_and_build (tree t,
/*done=*/false,
/*address_p=*/false);
}
- else if (koenig_p && TREE_CODE (function) == IDENTIFIER_NODE)
+ else if (koenig_p && identifier_p (function))
{
/* Do nothing; calling tsubst_copy_and_build on an identifier
would incorrectly perform unqualified lookup again.
@@ -13933,7 +13989,7 @@ tsubst_copy_and_build (tree t,
not appropriate, even if an unqualified-name was used
to denote the function. */
&& !DECL_FUNCTION_MEMBER_P (get_first_fn (function)))
- || TREE_CODE (function) == IDENTIFIER_NODE)
+ || identifier_p (function))
/* Only do this when substitution turns a dependent call
into a non-dependent call. */
&& type_dependent_expression_p_push (t)
@@ -13941,7 +13997,7 @@ tsubst_copy_and_build (tree t,
function = perform_koenig_lookup (function, call_args, false,
tf_none);
- if (TREE_CODE (function) == IDENTIFIER_NODE
+ if (identifier_p (function)
&& !any_type_dependent_arguments_p (call_args))
{
if (koenig_p && (complain & tf_warning_or_error))
@@ -13991,7 +14047,7 @@ tsubst_copy_and_build (tree t,
function = unq;
}
}
- if (TREE_CODE (function) == IDENTIFIER_NODE)
+ if (identifier_p (function))
{
if (complain & tf_error)
unqualified_name_lookup_error (function);
@@ -14004,6 +14060,9 @@ tsubst_copy_and_build (tree t,
if (DECL_P (function))
mark_used (function);
+ /* Put back tf_decltype for the actual call. */
+ complain |= decltype_flag;
+
if (TREE_CODE (function) == OFFSET_REF)
ret = build_offset_ref_call_from_tree (function, &call_args,
complain);
@@ -14471,12 +14530,6 @@ tsubst_copy_and_build (tree t,
declaration of the op() for later calls to lambda_function. */
complete_type (type);
- /* The capture list refers to closure members, so this needs to
- wait until after we finish instantiating the type. Also keep
- any captures that may have been added during instantiation. */
- LAMBDA_EXPR_CAPTURE_LIST (r)
- = chainon (RECUR (LAMBDA_EXPR_CAPTURE_LIST (t)),
- LAMBDA_EXPR_CAPTURE_LIST (r));
LAMBDA_EXPR_THIS_CAPTURE (r) = NULL_TREE;
RETURN (build_lambda_object (r));
@@ -19726,8 +19779,7 @@ type_dependent_expression_p (tree expression)
return false;
/* An unresolved name is always dependent. */
- if (TREE_CODE (expression) == IDENTIFIER_NODE
- || TREE_CODE (expression) == USING_DECL)
+ if (identifier_p (expression) || TREE_CODE (expression) == USING_DECL)
return true;
/* Some expression forms are never type-dependent. */
@@ -19832,7 +19884,7 @@ type_dependent_expression_p (tree expression)
if (type_dependent_expression_p (TREE_OPERAND (expression, 0)))
return true;
expression = TREE_OPERAND (expression, 1);
- if (TREE_CODE (expression) == IDENTIFIER_NODE)
+ if (identifier_p (expression))
return false;
}
/* SCOPE_REF with non-null TREE_TYPE is always non-dependent. */
@@ -19890,6 +19942,13 @@ instantiation_dependent_r (tree *tp, int *walk_subtrees,
case TREE_VEC:
return NULL_TREE;
+ case VAR_DECL:
+ case CONST_DECL:
+ /* A constant with a dependent initializer is dependent. */
+ if (value_dependent_expression_p (*tp))
+ return *tp;
+ break;
+
case TEMPLATE_PARM_INDEX:
return *tp;
@@ -19923,7 +19982,7 @@ instantiation_dependent_r (tree *tp, int *walk_subtrees,
return NULL_TREE;
case COMPONENT_REF:
- if (TREE_CODE (TREE_OPERAND (*tp, 1)) == IDENTIFIER_NODE)
+ if (identifier_p (TREE_OPERAND (*tp, 1)))
/* In a template, finish_class_member_access_expr creates a
COMPONENT_REF with an IDENTIFIER_NODE for op1 even if it isn't
type-dependent, so that we can check access control at
@@ -20167,8 +20226,7 @@ dependent_template_p (tree tmpl)
|| TREE_CODE (tmpl) == TEMPLATE_TEMPLATE_PARM)
return true;
/* So are names that have not been looked up. */
- if (TREE_CODE (tmpl) == SCOPE_REF
- || TREE_CODE (tmpl) == IDENTIFIER_NODE)
+ if (TREE_CODE (tmpl) == SCOPE_REF || identifier_p (tmpl))
return true;
/* So are member templates of dependent classes. */
if (TYPE_P (CP_DECL_CONTEXT (tmpl)))
@@ -20325,7 +20383,7 @@ resolve_typename_type (tree type, bool only_current_p)
find a TEMPLATE_DECL. Otherwise, we want to find a TYPE_DECL. */
if (!decl)
/*nop*/;
- else if (TREE_CODE (TYPENAME_TYPE_FULLNAME (type)) == IDENTIFIER_NODE
+ else if (identifier_p (TYPENAME_TYPE_FULLNAME (type))
&& TREE_CODE (decl) == TYPE_DECL)
{
result = TREE_TYPE (decl);
diff --git a/gcc/cp/search.c b/gcc/cp/search.c
index 4cc02ba7dfc..0ac7cdc2767 100644
--- a/gcc/cp/search.c
+++ b/gcc/cp/search.c
@@ -188,6 +188,14 @@ lookup_base (tree t, tree base, base_access access,
tree t_binfo;
base_kind bk;
+ /* "Nothing" is definitely not derived from Base. */
+ if (t == NULL_TREE)
+ {
+ if (kind_ptr)
+ *kind_ptr = bk_not_base;
+ return NULL_TREE;
+ }
+
if (t == error_mark_node || base == error_mark_node)
{
if (kind_ptr)
@@ -373,7 +381,7 @@ lookup_field_1 (tree type, tree name, bool want_type)
{
tree field;
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (name));
if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
|| TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
@@ -1182,7 +1190,7 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type,
|| xbasetype == error_mark_node)
return NULL_TREE;
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
+ gcc_assert (identifier_p (name));
if (TREE_CODE (xbasetype) == TREE_BINFO)
{
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index e909b984681..e3aeb817a52 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -536,7 +536,7 @@ simplify_loop_decl_cond (tree *cond_p, tree body)
tree
finish_goto_stmt (tree destination)
{
- if (TREE_CODE (destination) == IDENTIFIER_NODE)
+ if (identifier_p (destination))
destination = lookup_label (destination);
/* We warn about unused labels with -Wunused. That means we have to
@@ -1574,9 +1574,7 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope)
else
{
/* Set the cv qualifiers. */
- int quals = (current_class_ref
- ? cp_type_quals (TREE_TYPE (current_class_ref))
- : TYPE_UNQUALIFIED);
+ int quals = cp_type_quals (TREE_TYPE (object));
if (DECL_MUTABLE_P (decl))
quals &= ~TYPE_QUAL_CONST;
@@ -2001,7 +1999,7 @@ perform_koenig_lookup (tree fn, vec<tree, va_gc> *args, bool include_std,
}
/* Find the name of the overloaded function. */
- if (TREE_CODE (fn) == IDENTIFIER_NODE)
+ if (identifier_p (fn))
identifier = fn;
else if (is_overloaded_fn (fn))
{
@@ -2884,7 +2882,8 @@ outer_var_p (tree decl)
{
return ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
&& DECL_FUNCTION_SCOPE_P (decl)
- && DECL_CONTEXT (decl) != current_function_decl);
+ && (DECL_CONTEXT (decl) != current_function_decl
+ || parsing_nsdmi ()));
}
/* As above, but also checks that DECL is automatic. */
@@ -2967,7 +2966,7 @@ finish_id_expression (tree id_expression,
if (scope
&& (!TYPE_P (scope)
|| (!dependent_type_p (scope)
- && !(TREE_CODE (id_expression) == IDENTIFIER_NODE
+ && !(identifier_p (id_expression)
&& IDENTIFIER_TYPENAME_P (id_expression)
&& dependent_type_p (TREE_TYPE (id_expression))))))
{
@@ -2996,8 +2995,7 @@ finish_id_expression (tree id_expression,
the current class so that we can check later to see if
the meaning would have been different after the class
was entirely defined. */
- if (!scope && decl != error_mark_node
- && TREE_CODE (id_expression) == IDENTIFIER_NODE)
+ if (!scope && decl != error_mark_node && identifier_p (id_expression))
maybe_note_name_used_in_class (id_expression, decl);
/* Disallow uses of local variables from containing functions, except
@@ -3041,12 +3039,14 @@ finish_id_expression (tree id_expression,
return integral_constant_value (decl);
}
+ if (parsing_nsdmi ())
+ containing_function = NULL_TREE;
/* If we are in a lambda function, we can move out until we hit
1. the context,
2. a non-lambda function, or
3. a non-default capturing lambda function. */
- while (context != containing_function
- && LAMBDA_FUNCTION_P (containing_function))
+ else while (context != containing_function
+ && LAMBDA_FUNCTION_P (containing_function))
{
lambda_expr = CLASSTYPE_LAMBDA_EXPR
(DECL_CONTEXT (containing_function));
@@ -3168,8 +3168,7 @@ finish_id_expression (tree id_expression,
/* A template-id where the name of the template was not resolved
is definitely dependent. */
else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
- && (TREE_CODE (TREE_OPERAND (decl, 0))
- == IDENTIFIER_NODE))
+ && (identifier_p (TREE_OPERAND (decl, 0))))
dependent_p = true;
/* For anything except an overloaded function, just check its
type. */
@@ -5300,7 +5299,7 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
[expr.ref]), decltype(e) is defined as the type of the entity
named by e. If there is no such entity, or e names a set of
overloaded functions, the program is ill-formed. */
- if (TREE_CODE (expr) == IDENTIFIER_NODE)
+ if (identifier_p (expr))
expr = lookup_name (expr);
if (TREE_CODE (expr) == INDIRECT_REF)
@@ -6837,6 +6836,9 @@ cxx_eval_call_expression (const constexpr_call *old_call, tree t,
bool
reduced_constant_expression_p (tree t)
{
+ if (TREE_CODE (t) == PTRMEM_CST)
+ /* Even if we can't lower this yet, it's constant. */
+ return true;
/* FIXME are we calling this too much? */
return initializer_constant_valid_p (t, TREE_TYPE (t)) != NULL_TREE;
}
@@ -7007,6 +7009,13 @@ cxx_eval_array_reference (const constexpr_call *call, tree t,
*non_constant_p = true;
return t;
}
+ else if (tree_int_cst_lt (index, integer_zero_node))
+ {
+ if (!allow_non_constant)
+ error ("negative array subscript");
+ *non_constant_p = true;
+ return t;
+ }
i = tree_low_cst (index, 0);
if (TREE_CODE (ary) == CONSTRUCTOR)
return (*CONSTRUCTOR_ELTS (ary))[i].value;
@@ -8487,6 +8496,13 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
STRIP_NOPS (x);
if (is_this_parameter (x))
{
+ if (DECL_CONTEXT (x)
+ && !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (x)))
+ {
+ if (flags & tf_error)
+ error ("use of %<this%> in a constant expression");
+ return false;
+ }
if (want_rval && DECL_CONTEXT (x)
&& DECL_CONSTRUCTOR_P (DECL_CONTEXT (x)))
{
@@ -8967,7 +8983,7 @@ begin_lambda_type (tree lambda)
/* Create the new RECORD_TYPE for this lambda. */
type = xref_tag (/*tag_code=*/record_type,
name,
- /*scope=*/ts_within_enclosing_non_class,
+ /*scope=*/ts_lambda,
/*template_header_p=*/false);
}
@@ -9039,7 +9055,7 @@ tree
lambda_capture_field_type (tree expr)
{
tree type;
- if (type_dependent_expression_p (expr))
+ if (!TREE_TYPE (expr) || WILDCARD_TYPE_P (TREE_TYPE (expr)))
{
type = cxx_make_type (DECLTYPE_TYPE);
DECLTYPE_TYPE_EXPR (type) = expr;
@@ -9248,7 +9264,7 @@ lambda_proxy_type (tree ref)
if (REFERENCE_REF_P (ref))
ref = TREE_OPERAND (ref, 0);
type = TREE_TYPE (ref);
- if (!dependent_type_p (type))
+ if (type && !WILDCARD_TYPE_P (type))
return type;
type = cxx_make_type (DECLTYPE_TYPE);
DECLTYPE_TYPE_EXPR (type) = ref;
@@ -9661,7 +9677,11 @@ maybe_add_lambda_conv_op (tree type)
DECL_STATIC_FUNCTION_P (fn) = 1;
DECL_ARGUMENTS (fn) = copy_list (DECL_CHAIN (DECL_ARGUMENTS (callop)));
for (arg = DECL_ARGUMENTS (fn); arg; arg = DECL_CHAIN (arg))
- DECL_CONTEXT (arg) = fn;
+ {
+ /* Avoid duplicate -Wshadow warnings. */
+ DECL_NAME (arg) = NULL_TREE;
+ DECL_CONTEXT (arg) = fn;
+ }
if (nested)
DECL_INTERFACE_KNOWN (fn) = 1;
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 178b80aa24f..3cfc8690d89 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -469,6 +469,9 @@ build_cplus_new (tree type, tree init, tsubst_flags_t complain)
tree rval = build_aggr_init_expr (type, init);
tree slot;
+ if (!complete_type_or_maybe_complain (type, init, complain))
+ return error_mark_node;
+
/* Make sure that we're not trying to create an instance of an
abstract class. */
if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain))
@@ -1418,7 +1421,8 @@ strip_typedefs_expr (tree t)
}
case LAMBDA_EXPR:
- gcc_unreachable ();
+ error ("lambda-expression in a constant expression");
+ return error_mark_node;
default:
break;
@@ -1730,7 +1734,7 @@ is_overloaded_fn (tree x)
tree
dependent_name (tree x)
{
- if (TREE_CODE (x) == IDENTIFIER_NODE)
+ if (identifier_p (x))
return x;
if (TREE_CODE (x) != COMPONENT_REF
&& TREE_CODE (x) != OFFSET_REF
@@ -2024,11 +2028,12 @@ no_linkage_check (tree t, bool relaxed_p)
if (TYPE_PTRMEMFUNC_P (t))
goto ptrmem;
/* Lambda types that don't have mangling scope have no linkage. We
- check CLASSTYPE_LAMBDA_EXPR here rather than LAMBDA_TYPE_P because
+ check CLASSTYPE_LAMBDA_EXPR for error_mark_node because
when we get here from pushtag none of the lambda information is
set up yet, so we want to assume that the lambda has linkage and
fix it up later if not. */
if (CLASSTYPE_LAMBDA_EXPR (t)
+ && CLASSTYPE_LAMBDA_EXPR (t) != error_mark_node
&& LAMBDA_TYPE_EXTRA_SCOPE (t) == NULL_TREE)
return t;
/* Fall through. */
@@ -2486,7 +2491,7 @@ cp_tree_equal (tree t1, tree t2)
t1 = TREE_OPERAND (t1, 0);
for (code2 = TREE_CODE (t2);
CONVERT_EXPR_CODE_P (code2)
- || code1 == NON_LVALUE_EXPR;
+ || code2 == NON_LVALUE_EXPR;
code2 = TREE_CODE (t2))
t2 = TREE_OPERAND (t2, 0);
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 58ebcc0ab2d..4e42a9d3d7b 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -2467,7 +2467,7 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
scope, dtor_type);
return error_mark_node;
}
- if (TREE_CODE (dtor_type) == IDENTIFIER_NODE)
+ if (identifier_p (dtor_type))
{
/* In a template, names we can't find a match for are still accepted
destructor names, and we check them here. */
@@ -2588,7 +2588,7 @@ finish_class_member_access_expr (tree object, tree name, bool template_p,
dependent_type_p (object_type)
/* If NAME is just an IDENTIFIER_NODE, then the expression
is dependent. */
- || TREE_CODE (object) == IDENTIFIER_NODE
+ || identifier_p (object)
/* If NAME is "f<args>", where either 'f' or 'args' is
dependent, then the expression is dependent. */
|| (TREE_CODE (name) == TEMPLATE_ID_EXPR
@@ -2604,7 +2604,7 @@ finish_class_member_access_expr (tree object, tree name, bool template_p,
object = build_non_dependent_expr (object);
}
else if (c_dialect_objc ()
- && TREE_CODE (name) == IDENTIFIER_NODE
+ && identifier_p (name)
&& (expr = objc_maybe_build_component_ref (object, name)))
return expr;
@@ -2671,8 +2671,7 @@ finish_class_member_access_expr (tree object, tree name, bool template_p,
}
gcc_assert (CLASS_TYPE_P (scope));
- gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE
- || TREE_CODE (name) == BIT_NOT_EXPR);
+ gcc_assert (identifier_p (name) || TREE_CODE (name) == BIT_NOT_EXPR);
if (constructor_name_p (name, scope))
{
@@ -4015,7 +4014,7 @@ cp_build_binary_op (location_t location,
{
enum tree_code tcode0 = code0, tcode1 = code1;
- warn_for_div_by_zero (location, op1);
+ warn_for_div_by_zero (location, maybe_constant_value (op1));
if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE)
tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0)));
@@ -4051,7 +4050,7 @@ cp_build_binary_op (location_t location,
case TRUNC_MOD_EXPR:
case FLOOR_MOD_EXPR:
- warn_for_div_by_zero (location, op1);
+ warn_for_div_by_zero (location, maybe_constant_value (op1));
if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE
&& TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE
@@ -5067,8 +5066,7 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
arg = mark_lvalue_use (arg);
argtype = lvalue_type (arg);
- gcc_assert (TREE_CODE (arg) != IDENTIFIER_NODE
- || !IDENTIFIER_OPNAME_P (arg));
+ gcc_assert (!identifier_p (arg) || !IDENTIFIER_OPNAME_P (arg));
if (TREE_CODE (arg) == COMPONENT_REF && type_unknown_p (arg)
&& !really_overloaded_fn (TREE_OPERAND (arg, 1)))
@@ -6238,6 +6236,12 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
if (TREE_CODE (type) == VOID_TYPE)
return convert_to_void (expr, ICV_CAST, complain);
+ /* [class.abstract]
+ An abstract class shall not be used ... as the type of an explicit
+ conversion. */
+ if (abstract_virtuals_error_sfinae (ACU_CAST, type, complain))
+ return error_mark_node;
+
/* [expr.static.cast]
An expression e can be explicitly converted to a type T using a
@@ -7971,11 +7975,11 @@ convert_for_initialization (tree exp, tree type, tree rhs, int flags,
int savew = 0, savee = 0;
if (fndecl)
- savew = warningcount, savee = errorcount;
+ savew = warningcount + werrorcount, savee = errorcount;
rhs = initialize_reference (type, rhs, flags, complain);
if (fndecl)
{
- if (warningcount > savew)
+ if (warningcount + werrorcount > savew)
warning (0, "in passing argument %P of %q+D", parmnum, fndecl);
else if (errorcount > savee)
error ("in passing argument %P of %q+D", parmnum, fndecl);
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index d227a821d43..ca31610d66b 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -141,6 +141,9 @@ struct GTY((chain_next ("%h.next"))) pending_abstract_type {
/* Type which will be checked for abstractness. */
tree type;
+ /* Kind of use in an unnamed declarator. */
+ abstract_class_use use;
+
/* Position of the declaration. This is only needed for IDENTIFIER_NODEs,
because DECLs already carry locus information. */
location_t locus;
@@ -181,6 +184,7 @@ pat_compare (const void* val1, const void* val2)
static GTY ((param_is (struct pending_abstract_type)))
htab_t abstract_pending_vars = NULL;
+static int abstract_virtuals_error_sfinae (tree, tree, abstract_class_use, tsubst_flags_t);
/* This function is called after TYPE is completed, and will check if there
are pending declarations for which we still need to verify the abstractness
@@ -231,7 +235,8 @@ complete_type_check_abstract (tree type)
location. Notice that this is only needed if the decl is an
IDENTIFIER_NODE. */
input_location = pat->locus;
- abstract_virtuals_error (pat->decl, pat->type);
+ abstract_virtuals_error_sfinae (pat->decl, pat->type, pat->use,
+ tf_warning_or_error);
pat = pat->next;
}
}
@@ -244,11 +249,13 @@ complete_type_check_abstract (tree type)
/* If TYPE has abstract virtual functions, issue an error about trying
to create an object of that type. DECL is the object declared, or
- NULL_TREE if the declaration is unavailable. Returns 1 if an error
- occurred; zero if all was well. */
+ NULL_TREE if the declaration is unavailable, in which case USE specifies
+ the kind of invalid use. Returns 1 if an error occurred; zero if
+ all was well. */
-int
-abstract_virtuals_error_sfinae (tree decl, tree type, tsubst_flags_t complain)
+static int
+abstract_virtuals_error_sfinae (tree decl, tree type, abstract_class_use use,
+ tsubst_flags_t complain)
{
vec<tree, va_gc> *pure;
@@ -258,6 +265,10 @@ abstract_virtuals_error_sfinae (tree decl, tree type, tsubst_flags_t complain)
return 0;
type = TYPE_MAIN_VARIANT (type);
+ /* In SFINAE context, force instantiation. */
+ if (!(complain & tf_error))
+ complete_type (type);
+
/* If the type is incomplete, we register it within a hash table,
so that we can check again once it is completed. This makes sense
only for objects for which we have a declaration or at least a
@@ -267,8 +278,7 @@ abstract_virtuals_error_sfinae (tree decl, tree type, tsubst_flags_t complain)
void **slot;
struct pending_abstract_type *pat;
- gcc_assert (!decl || DECL_P (decl)
- || TREE_CODE (decl) == IDENTIFIER_NODE);
+ gcc_assert (!decl || DECL_P (decl) || identifier_p (decl));
if (!abstract_pending_vars)
abstract_pending_vars = htab_create_ggc (31, &pat_calc_hash,
@@ -280,6 +290,7 @@ abstract_virtuals_error_sfinae (tree decl, tree type, tsubst_flags_t complain)
pat = ggc_alloc_pending_abstract_type ();
pat->type = type;
pat->decl = decl;
+ pat->use = use;
pat->locus = ((decl && DECL_P (decl))
? DECL_SOURCE_LOCATION (decl)
: input_location);
@@ -308,8 +319,14 @@ abstract_virtuals_error_sfinae (tree decl, tree type, tsubst_flags_t complain)
error ("cannot declare variable %q+D to be of abstract "
"type %qT", decl, type);
else if (TREE_CODE (decl) == PARM_DECL)
- error ("cannot declare parameter %q+D to be of abstract type %qT",
- decl, type);
+ {
+ if (DECL_NAME (decl))
+ error ("cannot declare parameter %q+D to be of abstract type %qT",
+ decl, type);
+ else
+ error ("cannot declare parameter to be of abstract type %qT",
+ type);
+ }
else if (TREE_CODE (decl) == FIELD_DECL)
error ("cannot declare field %q+D to be of abstract type %qT",
decl, type);
@@ -318,14 +335,40 @@ abstract_virtuals_error_sfinae (tree decl, tree type, tsubst_flags_t complain)
error ("invalid abstract return type for member function %q+#D", decl);
else if (TREE_CODE (decl) == FUNCTION_DECL)
error ("invalid abstract return type for function %q+#D", decl);
- else if (TREE_CODE (decl) == IDENTIFIER_NODE)
+ else if (identifier_p (decl))
/* Here we do not have location information. */
error ("invalid abstract type %qT for %qE", type, decl);
else
error ("invalid abstract type for %q+D", decl);
}
- else
- error ("cannot allocate an object of abstract type %qT", type);
+ else switch (use)
+ {
+ case ACU_ARRAY:
+ error ("creating array of %qT, which is an abstract class type", type);
+ break;
+ case ACU_CAST:
+ error ("invalid cast to abstract class type %qT", type);
+ break;
+ case ACU_NEW:
+ error ("invalid new-expression of abstract class type %qT", type);
+ break;
+ case ACU_RETURN:
+ error ("invalid abstract return type %qT", type);
+ break;
+ case ACU_PARM:
+ error ("invalid abstract parameter type %qT", type);
+ break;
+ case ACU_THROW:
+ error ("expression of abstract class type %qT cannot "
+ "be used in throw-expression", type);
+ break;
+ case ACU_CATCH:
+ error ("cannot declare catch parameter to be of abstract "
+ "class type %qT", type);
+ break;
+ default:
+ error ("cannot allocate an object of abstract type %qT", type);
+ }
/* Only go through this once. */
if (pure->length ())
@@ -347,14 +390,24 @@ abstract_virtuals_error_sfinae (tree decl, tree type, tsubst_flags_t complain)
again. */
pure->truncate (0);
}
- else
- inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
- " since type %qT has pure virtual functions",
- type);
return 1;
}
+int
+abstract_virtuals_error_sfinae (tree decl, tree type, tsubst_flags_t complain)
+{
+ return abstract_virtuals_error_sfinae (decl, type, ACU_UNKNOWN, complain);
+}
+
+int
+abstract_virtuals_error_sfinae (abstract_class_use use, tree type,
+ tsubst_flags_t complain)
+{
+ return abstract_virtuals_error_sfinae (NULL_TREE, type, use, complain);
+}
+
+
/* Wrapper for the above function in the common case of wanting errors. */
int
@@ -363,6 +416,12 @@ abstract_virtuals_error (tree decl, tree type)
return abstract_virtuals_error_sfinae (decl, type, tf_warning_or_error);
}
+int
+abstract_virtuals_error (abstract_class_use use, tree type)
+{
+ return abstract_virtuals_error_sfinae (use, type, tf_warning_or_error);
+}
+
/* Print an error message for invalid use of an incomplete type.
VALUE is the expression that was used (or 0 if that isn't known)
and TYPE is the type that was invalid. DIAG_KIND indicates the
@@ -732,7 +791,7 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
will perform the dynamic initialization. */
if (value != error_mark_node
&& (TREE_SIDE_EFFECTS (value)
- || ! initializer_constant_valid_p (value, TREE_TYPE (value))))
+ || ! reduced_constant_expression_p (value)))
{
if (TREE_CODE (type) == ARRAY_TYPE
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (type)))
@@ -1181,7 +1240,7 @@ process_init_constructor_record (tree type, tree init,
latter case can happen in templates where lookup has to be
deferred. */
gcc_assert (TREE_CODE (ce->index) == FIELD_DECL
- || TREE_CODE (ce->index) == IDENTIFIER_NODE);
+ || identifier_p (ce->index));
if (ce->index != field
&& ce->index != DECL_NAME (field))
{
@@ -1307,7 +1366,7 @@ process_init_constructor_union (tree type, tree init,
{
if (TREE_CODE (ce->index) == FIELD_DECL)
;
- else if (TREE_CODE (ce->index) == IDENTIFIER_NODE)
+ else if (identifier_p (ce->index))
{
/* This can happen within a cast, see g++.dg/opt/cse2.C. */
tree name = ce->index;
@@ -1729,7 +1788,7 @@ build_functional_cast (tree exp, tree parms, tsubst_flags_t complain)
if (!complete_type_or_maybe_complain (type, NULL_TREE, complain))
return error_mark_node;
- if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain))
+ if (abstract_virtuals_error_sfinae (ACU_CAST, type, complain))
return error_mark_node;
/* [expr.type.conv]