This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] pedantic warning behavior when casting void* to ptr-to-func, 4.8 and 4.9


On Tue, Apr 15, 2014 at 6:12 PM, Richard Sandiford
<rdsandiford@googlemail.com> wrote:
> cc:ing Jason, who's the C++ maintainer.


FWIW: I created http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60850

>
> Daniel Gutson <daniel.gutson@tallertechnologies.com> writes:
>> ping for maintainer.
>>
>> Could this be considered for 4.8.3 please?
>>
>> Thanks,
>>
>>    Daniel.
>>
>>
>> On Tue, Apr 1, 2014 at 2:46 PM, Daniel Gutson
>> <daniel.gutson@tallertechnologies.com> wrote:
>>>
>>> I just realized I posted the patch in the wrong list.
>>>
>>>
>>> ---------- Forwarded message ----------
>>> From: Daniel Gutson <daniel.gutson@tallertechnologies.com>
>>> Date: Tue, Apr 1, 2014 at 10:43 AM
>>> Subject: [PATCH] pedantic warning behavior when casting void* to
>>> ptr-to-func, 4.8 and 4.9
>>> To: gcc Mailing List <gcc@gcc.gnu.org>
>>>
>>>
>>> Hi,
>>>
>>>    I observed two different behaviors in gcc 4.8.2 and 4.9 regarding
>>> the same issue, IMO both erroneous.
>>>
>>> Regarding 4.8.2, #pragma GCC diagnostic ignored "-pedantic" doesn't
>>> work in cases such as:
>>>     void* p = 0;
>>> #pragma GCC diagnostic ignored "-pedantic"
>>>     F* f2 = reinterpret_cast<F*>(p);
>>>
>>> (see testcase in the patch).
>>>
>>> The attached patch attempts to fix this issue. Since I no longer have
>>> write access, please
>>> apply this for me if correct (is the 4.8 branch still alive for adding fixes?).
>>>
>>> Regarding 4.9, gcc fails to complain at all when -pedantic is passed,
>>> even specifying -std=c++03.
>>> Please let me know if this is truly a bug, in which case I could also
>>> fix it for the latest version as well
>>> (if so, please let me know if I should look into trunk or any other branch).
>>>
>>> Thanks,
>>>
>>>    Daniel.
>>>
>>> 2014-03-31  Daniel Gutson  <daniel.gutson@tallertechnologies.com>
>>>
>>> gcc/cp/
>>>         * typeck.c (build_reinterpret_cast_1): Pass proper argument to
>>> warn() in pedantic.
>>>
>>> gcc/testsuite/g++.dg/
>>>         * diagnostic/pedantic.C: New test case.
>
> --- gcc-4.8.2-orig/gcc/cp/typeck.c      2014-03-31 22:29:42.736367936 -0300
> +++ gcc-4.8.2/gcc/cp/typeck.c   2014-03-31 14:26:43.536747050 -0300
> @@ -6639,7 +6639,7 @@
>            where possible, and it is necessary in some cases.  DR 195
>            addresses this issue, but as of 2004/10/26 is still in
>            drafting.  */
> -       warning (0, "ISO C++ forbids casting between pointer-to-function and pointer-to-object");
> +       warning (OPT_Wpedantic, "ISO C++ forbids casting between pointer-to-function and pointer-to-object");
>        return fold_if_not_in_template (build_nop (type, expr));
>      }
>    else if (TREE_CODE (type) == VECTOR_TYPE)
> --- gcc-4.8.2-orig/gcc/testsuite/g++.dg/diagnostic/pedantic.C   1969-12-31 21:00:00.000000000 -0300
> +++ gcc-4.8.2/gcc/testsuite/g++.dg/diagnostic/pedantic.C        2014-03-31 17:24:42.532607344 -0300
> @@ -0,0 +1,12 @@
> +// { dg-do compile }
> +// { dg-options "-pedantic" }
> +typedef void F(void);
> +
> +void foo()
> +{
> +    void* p = 0;
> +    F* f1 = reinterpret_cast<F*>(p);    // { dg-warning "ISO" }
> +#pragma GCC diagnostic ignored "-pedantic"
> +    F* f2 = reinterpret_cast<F*>(p);
> +}
> +



-- 

Daniel F. Gutson
Chief Engineering Officer, SPD


San Lorenzo 47, 3rd Floor, Office 5

CÃrdoba, Argentina


Phone: +54 351 4217888 / +54 351 4218211

Skype: dgutson


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]