[Bug c++/70844] spurious -Wuseless-cast warning with inherited constructors

2017-05-02 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70844

--- Comment #2 from Marc Glisse  ---
*** Bug 80599 has been marked as a duplicate of this bug. ***

[Bug c++/70844] spurious -Wuseless-cast warning with inherited constructors

2017-01-31 Thread rs2740 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70844

TC  changed:

   What|Removed |Added

 CC||rs2740 at gmail dot com

--- Comment #1 from TC  ---
The attached test case doesn't reproduce in 6.2.0, presumably due to the fix
for 70972. The following (slightly modified) test case still produces a
-Wuseless-cast warning on trunk and 6.3.0:

struct base {
base (int const &);
};

struct derived : public base {
using base::base;
};

derived d(0);

What appears to be happening is that the inheriting constructor calls
forward_parm to perfectly forward the arguments, which in turn calls
build_static_cast to construct the equivalent of static_cast(p)
where p is of type const int &, which emits a -Wuseless-cast warning. 

Consistent with this hypothesis, 6.1 emits a warning for the original test case
because it was emitting the equivalent of static_cast(p) where `p`'s type
is `int`; GCC >= 6.2, which has the 70972 fix, emits the equivalent of
static_cast(p), which doesn't trigger the warning. GCC < 6 doesn't have
forward_parm and doesn't unconditionally build a static_cast, so doesn't hit
this warning either.