diff options
author | Jason Merrill <jason@redhat.com> | 2019-11-05 18:50:08 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2019-11-05 18:50:08 -0500 |
commit | f22f817cbdffe5b4e7d0ba7ab0eeb56ee61b3b72 (patch) | |
tree | 297e198f67433c4deed3dde93c59355d41a91c01 | |
parent | a81ffd93b83c4be250514ff385b5b88fa5c3835b (diff) | |
download | gcc-f22f817cbdffe5b4e7d0ba7ab0eeb56ee61b3b72.zip gcc-f22f817cbdffe5b4e7d0ba7ab0eeb56ee61b3b72.tar.gz gcc-f22f817cbdffe5b4e7d0ba7ab0eeb56ee61b3b72.tar.bz2 |
Various small C++ changes.
Wrappers for lookup_qualified_name and build_x_binary_op to make calling
them more convenient in places, and a function named contextual_conv_bool
for places that want contextual conversion to bool.
I noticed that we weren't showing the declaration location when we complain
about a call to a non-constexpr function where a constant expression is
required.
If maybe_instantiate_noexcept doesn't actually instantiate, there's no
reason for it to mess with clones.
* constexpr.c (explain_invalid_constexpr_fn): Show location of fn.
* pt.c (maybe_instantiate_noexcept): Only update clones if we
instantiated.
* typeck.c (contextual_conv_bool): New.
* name-lookup.c (lookup_qualified_name): Add wrapper overload taking
C string rather than identifier.
* parser.c (cp_parser_userdef_numeric_literal): Use it.
* rtti.c (emit_support_tinfos): Use it.
* cp-tree.h (ovl_op_identifier): Change to inline functions.
(build_x_binary_op): Add wrapper with fewer parms.
From-SVN: r277862
-rw-r--r-- | gcc/cp/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 5 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 17 | ||||
-rw-r--r-- | gcc/cp/name-lookup.c | 10 | ||||
-rw-r--r-- | gcc/cp/name-lookup.h | 3 | ||||
-rw-r--r-- | gcc/cp/parser.c | 5 | ||||
-rw-r--r-- | gcc/cp/pt.c | 14 | ||||
-rw-r--r-- | gcc/cp/rtti.c | 2 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 13 | ||||
-rw-r--r-- | gcc/cp/typeck2.c | 3 |
10 files changed, 66 insertions, 22 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 00f5218..f6abb84 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,19 @@ +2019-11-04 Jason Merrill <jason@redhat.com> + + * constexpr.c (explain_invalid_constexpr_fn): Show location of fn. + + * pt.c (maybe_instantiate_noexcept): Only update clones if we + instantiated. + + * typeck.c (contextual_conv_bool): New. + + * name-lookup.c (lookup_qualified_name): Add wrapper overload taking + C string rather than identifier. + * parser.c (cp_parser_userdef_numeric_literal): Use it. + * rtti.c (emit_support_tinfos): Use it. + * cp-tree.h (ovl_op_identifier): Change to inline functions. + (build_x_binary_op): Add wrapper with fewer parms. + 2019-11-05 Jason Merrill <jason@redhat.com> * decl2.c (mark_used): Diagnose use of a function with unsatisfied diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 72de2ef..ce910cd 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -934,7 +934,10 @@ explain_invalid_constexpr_fn (tree fun) if (!DECL_DEFAULTED_FN (fun) && !LAMBDA_TYPE_P (CP_DECL_CONTEXT (fun)) && !is_instantiation_of_constexpr (fun)) - return; + { + inform (DECL_SOURCE_LOCATION (fun), "%qD declared here", fun); + return; + } if (diagnosed == NULL) diagnosed = new hash_set<tree>; if (diagnosed->add (fun)) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 4b9aea6..58d7d01 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -270,9 +270,6 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; then deletes the entire object. */ #define deleting_dtor_identifier cp_global_trees[CPTI_DELETING_DTOR_IDENTIFIER] -#define ovl_op_identifier(ISASS, CODE) (OVL_OP_INFO(ISASS, CODE)->identifier) -#define assign_op_identifier (ovl_op_info[true][OVL_OP_NOP_EXPR].identifier) -#define call_op_identifier (ovl_op_info[false][OVL_OP_CALL_EXPR].identifier) /* The name used for conversion operators -- but note that actual conversion functions use special identifiers outside the identifier table. */ @@ -5816,6 +5813,12 @@ extern GTY(()) unsigned char ovl_op_alternate[OVL_OP_MAX]; #define IDENTIFIER_OVL_OP_FLAGS(NODE) \ (IDENTIFIER_OVL_OP_INFO (NODE)->flags) +inline tree ovl_op_identifier (bool isass, tree_code code) +{ return OVL_OP_INFO(isass, code)->identifier; } +inline tree ovl_op_identifier (tree_code code) { return ovl_op_identifier (false, code); } +#define assign_op_identifier (ovl_op_info[true][OVL_OP_NOP_EXPR].identifier) +#define call_op_identifier (ovl_op_info[false][OVL_OP_CALL_EXPR].identifier) + /* A type-qualifier, or bitmask therefore, using the TYPE_QUAL constants. */ @@ -7422,6 +7425,7 @@ enum compare_bounds_t { bounds_none, bounds_either, bounds_first }; extern bool cxx_mark_addressable (tree, bool = false); extern int string_conv_p (const_tree, const_tree, int); extern tree cp_truthvalue_conversion (tree); +extern tree contextual_conv_bool (tree, tsubst_flags_t); extern tree condition_conversion (tree); extern tree require_complete_type (tree); extern tree require_complete_type_sfinae (tree, tsubst_flags_t); @@ -7470,6 +7474,13 @@ extern tree build_x_binary_op (const op_location_t &, enum tree_code, tree, enum tree_code, tree *, tsubst_flags_t); +inline tree build_x_binary_op (const op_location_t &loc, + enum tree_code code, tree arg1, tree arg2, + tsubst_flags_t complain) +{ + return build_x_binary_op (loc, code, arg1, TREE_CODE (arg1), arg2, + TREE_CODE (arg2), NULL, complain); +} extern tree build_x_array_ref (location_t, tree, tree, tsubst_flags_t); extern tree build_x_unary_op (location_t, diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 9ef1ed9..cbb6169 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1273,7 +1273,7 @@ get_class_binding_direct (tree klass, tree name, bool want_type) special function creation as necessary. */ tree -get_class_binding (tree klass, tree name, bool want_type) +get_class_binding (tree klass, tree name, bool want_type /*=false*/) { klass = complete_type (klass); @@ -5943,7 +5943,7 @@ suggest_alternative_in_scoped_enum (tree name, tree scoped_enum) tree lookup_qualified_name (tree scope, tree name, int prefer_type, bool complain, - bool find_hidden) + bool find_hidden /*=false*/) { tree t = NULL_TREE; @@ -5967,6 +5967,12 @@ lookup_qualified_name (tree scope, tree name, int prefer_type, bool complain, return t; } +/* Wrapper for the above that takes a string argument. The function name is + not at the beginning of the line to keep this wrapper out of etags. */ + +tree lookup_qualified_name (tree t, const char *p, int wt, bool c, bool fh) +{ return lookup_qualified_name (t, get_identifier (p), wt, c, fh); } + /* [namespace.qual] Accepts the NAME to lookup and its qualifying SCOPE. Returns the name/type pair found into the cxx_binding *RESULT, diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h index 0b7bf83..f529511 100644 --- a/gcc/cp/name-lookup.h +++ b/gcc/cp/name-lookup.h @@ -287,7 +287,8 @@ inline tree get_global_binding (tree id) { return get_namespace_binding (NULL_TREE, id); } -extern tree lookup_qualified_name (tree, tree, int, bool, /*hidden*/bool = false); +extern tree lookup_qualified_name (tree, tree, int = 0, bool = true, /*hidden*/bool = false); +extern tree lookup_qualified_name (tree t, const char *p, int = 0, bool = true, bool = false); extern tree lookup_name_nonclass (tree); extern bool is_local_extern (tree); extern bool pushdecl_class_level (tree); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index bce7161..11468c0 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -4546,9 +4546,8 @@ cp_parser_userdef_numeric_literal (cp_parser *parser) if (i14 && ext) { - tree cxlit = lookup_qualified_name (std_node, - get_identifier ("complex_literals"), - 0, false, false); + tree cxlit = lookup_qualified_name (std_node, "complex_literals", + 0, false); if (cxlit == error_mark_node) { /* No <complex>, so pedwarn and use GNU semantics. */ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 172d3d8..b8f8f6d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -24862,14 +24862,14 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) TREE_TYPE (fn) = build_exception_variant (fntype, spec); if (orig_fn) TREE_TYPE (orig_fn) = TREE_TYPE (fn); - } - FOR_EACH_CLONE (clone, fn) - { - if (TREE_TYPE (clone) == fntype) - TREE_TYPE (clone) = TREE_TYPE (fn); - else - TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec); + FOR_EACH_CLONE (clone, fn) + { + if (TREE_TYPE (clone) == fntype) + TREE_TYPE (clone) = TREE_TYPE (fn); + else + TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec); + } } return true; diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index b3d579f..1ba4a46 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -1553,7 +1553,7 @@ emit_support_tinfos (void) /* Look for a defined class. */ tree bltn_type = lookup_qualified_name - (abi_node, get_identifier ("__fundamental_type_info"), true, false, false); + (abi_node, "__fundamental_type_info", true, false); if (TREE_CODE (bltn_type) != TYPE_DECL) return; diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index eefb83d..bf2502a 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5931,15 +5931,22 @@ cp_truthvalue_conversion (tree expr) return c_common_truthvalue_conversion (input_location, expr); } +/* Returns EXPR contextually converted to bool. */ + +tree +contextual_conv_bool (tree expr, tsubst_flags_t complain) +{ + return perform_implicit_conversion_flags (boolean_type_node, expr, + complain, LOOKUP_NORMAL); +} + /* Just like cp_truthvalue_conversion, but we want a CLEANUP_POINT_EXPR. This is a low-level function; most callers should use maybe_convert_cond. */ tree condition_conversion (tree expr) { - tree t; - t = perform_implicit_conversion_flags (boolean_type_node, expr, - tf_warning_or_error, LOOKUP_NORMAL); + tree t = contextual_conv_bool (expr, tf_warning_or_error); if (!processing_template_decl) t = fold_build_cleanup_point_expr (boolean_type_node, t); return t; diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 2402c38..7884d42 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -938,7 +938,8 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags) constants. */ bool -check_narrowing (tree type, tree init, tsubst_flags_t complain, bool const_only) +check_narrowing (tree type, tree init, tsubst_flags_t complain, + bool const_only/*= false*/) { tree ftype = unlowered_expr_type (init); bool ok = true; |