Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions gcc/c-family/c.opt
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,14 @@ Wformat-truncation=
C ObjC C++ LTO ObjC++ Joined RejectNegative UInteger Var(warn_format_trunc) Warning LangEnabledBy(C ObjC C++ LTO ObjC++,Wformat=, warn_format >= 1, 0) IntegerRange(0, 2)
Warn about calls to snprintf and similar functions that truncate output.

Wfunctional-cast
C++ ObjC++ Warning Alias(Wfunctional-cast=, 4, 0)
Warn if a functional-style cast involves potentially-unsafe constructs.

Wfunctional-cast=
C++ ObjC++ Joined RejectNegative UInteger Var(warn_functional_cast) Warning LangEnabledBy(C++ ObjC++,Wall || Wextra, code == OPT_Wextra ? 5 : 4, 0) IntegerRange(0, 5)
Warn if a functional-style cast is not accomplished by direct-initialization.

Wif-not-aligned
C ObjC C++ ObjC++ Var(warn_if_not_aligned) Init(1) Warning
Warn when the field in a struct is not aligned.
Expand Down
5 changes: 3 additions & 2 deletions gcc/cp/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7576,7 +7576,8 @@ build_op_delete_call (enum tree_code code, tree addr, tree size,
rtype = cv_unqualified (rtype);
rtype = TYPE_POINTER_TO (rtype);
addr = cp_convert (rtype, oaddr, complain);
destroying = build_functional_cast (input_location,
destroying = build_functional_cast (UNKNOWN_LOCATION,
input_location,
destroying, NULL_TREE,
complain);
}
Expand Down Expand Up @@ -11072,7 +11073,7 @@ build_new_method_call (tree instance, tree fns, vec<tree, va_gc> **args,
basetype, name))
inform (input_location, "for a function-style cast, remove the "
"redundant %<::%D%>", name);
call = build_functional_cast (input_location, basetype,
call = build_functional_cast (UNKNOWN_LOCATION, input_location, basetype,
build_tree_list_vec (user_args),
complain);
return call;
Expand Down
13 changes: 9 additions & 4 deletions gcc/cp/cp-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
IMPLICIT_CONV_EXPR_BRACED_INIT (in IMPLICIT_CONV_EXPR)
PACK_EXPANSION_AUTO_P (in *_PACK_EXPANSION)
3: IMPLICIT_RVALUE_P (in NON_LVALUE_EXPR or STATIC_CAST_EXPR)
FUNCTIONAL_CAST_P (in CAST_EXPR)
ICS_BAD_FLAG (in _CONV)
FN_TRY_BLOCK_P (in TRY_BLOCK)
BIND_EXPR_BODY_BLOCK (in BIND_EXPR)
Expand Down Expand Up @@ -4045,6 +4046,9 @@ struct GTY(()) lang_decl {
#define IMPLICIT_RVALUE_P(NODE) \
TREE_LANG_FLAG_3 (TREE_CHECK2 ((NODE), NON_LVALUE_EXPR, STATIC_CAST_EXPR))

#define FUNCTIONAL_CAST_P(NODE) \
TREE_LANG_FLAG_3 (TREE_CHECK ((NODE), CAST_EXPR))

#define NEW_EXPR_USE_GLOBAL(NODE) \
TREE_LANG_FLAG_0 (NEW_EXPR_CHECK (NODE))
#define DELETE_EXPR_USE_GLOBAL(NODE) \
Expand Down Expand Up @@ -5565,6 +5569,7 @@ enum tsubst_flags {
tf_tst_ok = 1 << 12, /* Allow a typename-specifier to name
a template (C++17 or later). */
tf_dguide = 1 << 13, /* Building a deduction guide from a ctor. */
tf_functional_cast = 1 << 14,
/* Convenient substitution flags combinations. */
tf_warning_or_error = tf_warning | tf_error
};
Expand Down Expand Up @@ -8045,8 +8050,8 @@ extern tree build_const_cast (location_t, tree, tree,
extern tree build_c_cast (location_t, tree, tree);
extern cp_expr build_c_cast (location_t loc, tree type,
cp_expr expr);
extern tree cp_build_c_cast (location_t, tree, tree,
tsubst_flags_t);
extern tree cp_build_c_cast (location_t, location_t, tree,
tree, tsubst_flags_t);
extern cp_expr build_x_modify_expr (location_t, tree,
enum tree_code, tree,
tree, tsubst_flags_t);
Expand Down Expand Up @@ -8185,8 +8190,8 @@ extern tree build_scoped_ref (tree, tree, tree *);
extern tree build_x_arrow (location_t, tree,
tsubst_flags_t);
extern tree build_m_component_ref (tree, tree, tsubst_flags_t);
extern tree build_functional_cast (location_t, tree, tree,
tsubst_flags_t);
extern tree build_functional_cast (location_t, location_t, tree,
tree, tsubst_flags_t);
extern tree add_exception_specifier (tree, tree, tsubst_flags_t);
extern tree merge_exception_specifiers (tree, tree);
extern void set_target_expr_eliding (tree);
Expand Down
5 changes: 3 additions & 2 deletions gcc/cp/decl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7139,7 +7139,7 @@ reshape_init (tree type, tree init, tsubst_flags_t complain)
{
warning_sentinel w (warn_useless_cast);
warning_sentinel w2 (warn_ignored_qualifiers);
return cp_build_c_cast (input_location, type, elt,
return cp_build_c_cast (UNKNOWN_LOCATION, input_location, type, elt,
tf_warning_or_error);
}
else
Expand Down Expand Up @@ -7446,7 +7446,8 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
new_init = build_cplus_new (type, init_code, tf_none);
else if (CLASS_TYPE_P (type)
&& (!init || TREE_CODE (init) == TREE_LIST))
new_init = build_functional_cast (input_location, type,
new_init = build_functional_cast (UNKNOWN_LOCATION,
input_location, type,
init, tf_none);
if (new_init)
{
Expand Down
4 changes: 3 additions & 1 deletion gcc/cp/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13950,7 +13950,9 @@ ordinary_loc_of (line_maps *lmaps, location_t from)
static module_state **
get_module_slot (tree name, module_state *parent, bool partition, bool insert)
{
module_state_hash::compare_type ct (name, uintptr_t (parent) | partition);
module_state_hash::compare_type ct (name,
(reinterpret_cast<uintptr_t> (parent)
| partition));
hashval_t hv = module_state_hash::hash (ct);

return modules_hash->find_slot_with_hash (ct, hv, insert ? INSERT : NO_INSERT);
Expand Down
9 changes: 5 additions & 4 deletions gcc/cp/name-lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,23 @@ struct GTY(()) binding_slot {
}
bool is_lazy () const
{
return bool (uintptr_t (u.binding) & 1);
return bool (reinterpret_cast<uintptr_t> (u.binding) & 1);
}
void set_lazy (unsigned snum)
{
gcc_checking_assert (!u.binding);
u.binding = tree (uintptr_t ((snum << 1) | 1));
u.binding = reinterpret_cast<tree> (uintptr_t ((snum << 1) | 1));
}
void or_lazy (unsigned snum)
{
gcc_checking_assert (is_lazy ());
u.binding = tree (uintptr_t (u.binding) | (snum << 1));
u.binding = reinterpret_cast<tree> (reinterpret_cast<uintptr_t> (u.binding)
| (snum << 1));
}
unsigned get_lazy () const
{
gcc_checking_assert (is_lazy ());
return unsigned (uintptr_t (u.binding) >> 1);
return unsigned (reinterpret_cast<uintptr_t> (u.binding) >> 1);
}
};

Expand Down
4 changes: 2 additions & 2 deletions gcc/cp/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32032,8 +32032,8 @@ cp_parser_functional_cast (cp_parser* parser, tree type)
finishing at the closing paren. */
location_t combined_loc = make_location (start_loc, start_loc,
parser->lexer);
cast = build_functional_cast (combined_loc, type, expression_list,
tf_warning_or_error);
cast = build_functional_cast (start_loc, combined_loc, type, expression_list,
tf_functional_cast | tf_warning_or_error);

/* [expr.const]/1: In an integral constant expression "only type
conversions to integral or enumeration type can be used". */
Expand Down
5 changes: 4 additions & 1 deletion gcc/cp/pt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20377,7 +20377,10 @@ tsubst_copy_and_build (tree t,
switch (TREE_CODE (t))
{
case CAST_EXPR:
r = build_functional_cast (input_location, type, op, complain);
if (FUNCTIONAL_CAST_P (t))
complain |= tf_functional_cast;
r = build_functional_cast (UNKNOWN_LOCATION, input_location, type,
op, complain);
break;
case REINTERPRET_CAST_EXPR:
r = build_reinterpret_cast (input_location, type, op, complain);
Expand Down
8 changes: 4 additions & 4 deletions gcc/cp/semantics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3243,7 +3243,7 @@ finish_compound_literal (tree type, tree compound_literal,
that it came from T{} rather than T({}). */
CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
compound_literal = build_tree_list (NULL_TREE, compound_literal);
return build_functional_cast (input_location, type,
return build_functional_cast (UNKNOWN_LOCATION, input_location, type,
compound_literal, complain);
}

Expand Down Expand Up @@ -6579,15 +6579,15 @@ cp_omp_finish_iterators (tree iter)
begin = mark_rvalue_use (begin);
end = mark_rvalue_use (end);
step = mark_rvalue_use (step);
begin = cp_build_c_cast (input_location, type, begin,
begin = cp_build_c_cast (UNKNOWN_LOCATION, input_location, type, begin,
tf_warning_or_error);
end = cp_build_c_cast (input_location, type, end,
end = cp_build_c_cast (UNKNOWN_LOCATION, input_location, type, end,
tf_warning_or_error);
orig_step = step;
if (!processing_template_decl)
step = orig_step = save_expr (step);
tree stype = POINTER_TYPE_P (type) ? sizetype : type;
step = cp_build_c_cast (input_location, stype, step,
step = cp_build_c_cast (UNKNOWN_LOCATION, input_location, stype, step,
tf_warning_or_error);
if (POINTER_TYPE_P (type) && !processing_template_decl)
{
Expand Down
Loading