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
This commit is contained in:
Jason Merrill 2019-11-05 18:50:08 -05:00 committed by Jason Merrill
parent a81ffd93b8
commit f22f817cbd
10 changed files with 66 additions and 22 deletions

View file

@ -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

View file

@ -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))

View file

@ -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,

View file

@ -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,

View file

@ -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);

View file

@ -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. */

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;