https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90309
Bug ID: 90309
Summary: Spurious warning shift-negative-value
Product: gcc
Version: 8.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: philipp.lucas at siemens dot com
Target Milestone: ---
Created attachment 46272
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46272&action=edit
Test case
Consider the following code:
struct O {
char c;
};
typedef void (O::*MP)(void);
struct Uv : O {
virtual void v();
void f();
};
MP mfv=static_cast(&Uv::f);
When compiled for MIPS, this triggers the following warning:
> mips-sde-elf-gcc -c -Wshift-negative-value shift.cpp
warning: left shift of negative value [-Wshift-negative-value]
MP mfv=static_cast(&Uv::f);
The reason for this seems to be the left shift in
build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p,
tsubst_flags_t complain)
...
if (!integer_zerop (n))
{
if (TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_delta)
n = cp_build_binary_op (input_location,
LSHIFT_EXPR, n, integer_one_node,
complain);
delta = cp_build_binary_op (input_location,
PLUS_EXPR, delta, n, complain);
}
where n->int_cst.val == -4 , which is to be expected.
I do not think such an internally generated shift should give rise to a user
visible warning, which will make the user search in vain for a shift in the
original code.