This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR c++/80544 strip cv-quals from cast results
- From: Jason Merrill <jason at redhat dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>, Nathan Sidwell <nathan at acm dot org>
- Date: Wed, 24 May 2017 14:50:22 -0400
- Subject: Re: [PATCH] PR c++/80544 strip cv-quals from cast results
- Authentication-results: sourceware.org; auth=none
- References: <20170427165907.GL5109@redhat.com> <CADzB+2nMhFnDrqk1jbE3nDx7b1hukJuWB3J5pSt=dGXmceOVPA@mail.gmail.com> <20170523180046.GG12306@redhat.com> <CADzB+2=yocABQpVueGU4rTwLbTwn1f8wkT2FEUC4ZS0=Ai+oig@mail.gmail.com> <20170524142022.GJ12306@redhat.com>
On Wed, May 24, 2017 at 10:20 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
> On 23/05/17 16:26 -0400, Jason Merrill wrote:
>>
>> On Tue, May 23, 2017 at 2:00 PM, Jonathan Wakely <jwakely@redhat.com>
>> wrote:
>>>
>>> On 19/05/17 15:14 -0400, Jason Merrill wrote:
>>>>
>>>>
>>>> On Thu, Apr 27, 2017 at 12:59 PM, Jonathan Wakely <jwakely@redhat.com>
>>>> wrote:
>>>>>
>>>>>
>>>>> I also tried to add a warning like EDG's (see the PR) but it gave a
>>>>> false positive for direct-list-init of scoped enums (P0138R2, r240449)
>>>>> because that code goes through build_c_cast to perform the conversion,
>>>>> so looks like a cast to my new warning.
>>>>
>>>>
>>>>
>>>> The enum init code could strip the cv-quals when calling build_c_cast
>>>> to avoid the warning.
>>>
>>>
>>>
>>> Thanks, that works. I don't think this warning fits under any existing
>>> option, so I'll add a new one. -Wuseless-cast-qual maybe? Or is that
>>> too close to -Wuseless-cast and -Wcast-qual and would cause confusion?
>>
>>
>> -Wcast-rvalue-qual ?
>
>
> I realised that -Wignored-qualifiers is a good fit. That warns about
> ignored cv-qualifiers on return types, which is a very similar case.
>
> This patch adds a new function to conditionally warn and calls that
> from the build_*_cast functions after they produce a valid result. I
> originally put the warnings next to the cv_unqualified calls that
> strip the quals, but was getting duplicate warnings when build_cp_cast
> calls more than one of the build_*_cast_1 functions.
>
> This also removes the unnecessary check for reference types that
> Nathan pointed out.
>
> Tested x86_64-linux and powerpc64-linux. OK for trunk?
> +/*
> + Warns if the cast ignores cv-qualifiers on TYPE.
> + */
The GCC sources don't put /* and */ on their own line. OK with that
change, thanks!
Jason