C++ PATCH for c++/87357, missing -Wconversion warning

Marek Polacek polacek@redhat.com
Wed Sep 19 16:03:00 GMT 2018


On Wed, Sep 19, 2018 at 09:51:44AM -0600, Martin Sebor wrote:
> On 09/18/2018 09:47 PM, Marek Polacek wrote:
> > As I mentioned in the PR, [class.conv.fct] says "A conversion function is never
> > used to convert a (possibly cv-qualified) object to the (possibly cv-qualified)
> > same object type (or a reference to it), to a (possibly cv-qualified) base class
> > of that type (or a reference to it), or to (possibly cv-qualified) void." but I
> > noticed we weren't warning about
> > 
> > struct X {
> >   operator X();
> > };
> > 
> > (and there are no tests for this case) because comparing types directly only
> > works for TYPE_CANONICAL, otherwise we have to use same_type_*.
> > 
> > I'm also changing the warning about 'void' since we can't form a reference to
> > void.
> 
> Since you're changing the text of the void warning it would also
> be nice to add quoting around the type name if it doesn't involve
> adjusting too many tests.  But...

Only two tests besides the new one trigger this warning, so that would be
trivial.

> ...
> > +struct B { };
> > +
> > +struct X : public B {
> > +  operator X(); // { dg-warning "3:conversion to the same type will never use a type conversion operator" }
> 
> Is the operator function mentioned in the warning?

Nope, just what the dg-warning says.

> If not, mentioning it would make it clearer which of a set of
> operators is not going to be used (when there are multiple like
> in this test) and also make it easier to distinguish one from
> the others if they're on the same line (e.g., if the class is
> the result of macro expansion).

Good idea.  Maybe let's commit this first (a bugfix) and then I can add
the types printing (an enhancement)?

Marek



More information about the Gcc-patches mailing list