Closed p5pRT closed 7 years ago
Hello\,
when building a code that includes
#include "EXTERN.h #include "perl.h"
with GCC's -Wcast-qual option\, I get many warnings about discarding const qualifiers like this:
$ printf '#include "EXTERN.h"\n#include "perl.h"\n' | gcc -Wcast-qual -I/usr/lib64/perl5/CORE -c -x c -
In file included from /usr/lib64/perl5/CORE/hv.h:629:0\,
from /usr/lib64/perl5/CORE/perl.h:3740\,
from \
This makes difficult to spot issues in non-perl code and people complain (https://bugzilla.redhat.com/show_bug.cgi?id=1242980).
Series of three patches is attached that tries to fix this issue:
First patch fixes hash functions in hv_func.h. Because their input is already const and their output does not rely pointers to input data\, this patch seems simple and non-controversial.
Second patch touches utf8.h and utfebcdic.h. It changes dereferencing string bytes in is_UTF8-* check macros. While these are macros without argument types\, I think its reasonable to assume the input string does not change during the check\, so the change is desired. The only unusual thing is the changed code was originally generated by a script\, then hand-editted\, and then comes my patch. I did not try to locate the disfunctional (or deleted?) generator in regen/regcharclass.pl and ammend it.
The third and last patch touches utf8_hop* functions. This is the most controversal change as it changes their prototype. I cannot see a way how to get rid of the warnings there without changing prototype. I looked into glibc sources how char *strchr(const char *\, int) is solved. It isn't. It also produces many warnings. Here I doubt about helpfullness of the -Wcast-qual warnings.
-- Petr
Petr Pisar wrote:
I cannot see a way how to
get rid of the warnings there without changing prototype. I looked into glibc sources how char *strchr(const char *\, int) is solved. It isn't. It also produces many warnings. Here I doubt about helpfullness of the -Wcast-qual warnings.
Indeed. We're not going to want to change prototypes here\, for the same reasons that the strchr() prototype is appropriate as it is. The code is correct\, and there's no reasonable way to avoid these warnings.
Your first two patches seem OK. We're happy with that kind of localised change to avoid warnings.
-zefram
The RT System itself - Status changed from 'new' to 'open'
On Thu\, Nov 24\, 2016 at 01:05:58PM -0800\, Zefram via RT wrote:
Indeed. We're not going to want to change prototypes here\, for the same reasons that the strchr() prototype is appropriate as it is. The code is correct\, and there's no reasonable way to avoid these warnings.
I searched Perl sources to see how utf8_hop is used and it's realy mix of all the ways.
Should I bother with compiler pragmata to silent the warning? GCC-specific code would be:
char *foo(const char *a) { #if defined __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-qual" #endif return (char *)a; #if defined __GNUC__ #pragma GCC diagnostic pop #endif }
I do not want to clutter the sources.
Your first two patches seem OK. We're happy with that kind of localised change to avoid warnings.
Thanks for reviewing the patches.
-- Petr
On Fri\, Nov 25\, 2016 at 10:14:41AM -0500\, Andy Lester wrote:
Should I bother with compiler pragmata to silent the warning? [...] I would be in favor of doing that if it was wrapped in a macro. It would be good to have it explicitly obvious that we are casting away const\, so that we can have the compiler flag the ones we don't mean to cast away.
Me either. I searched the sources again and I found there had already been GCC_DIAG_IGNORE and GCC_DIAG_RESTORE macros for that.
The attached patch that replaces the third patch from the original patch set uses them to silence the warnings in utf8_hop functions.
-- Petr
On Mon\, 28 Nov 2016 04:22:12 -0800\, ppisar wrote:
On Fri\, Nov 25\, 2016 at 10:14:41AM -0500\, Andy Lester wrote:
Should I bother with compiler pragmata to silent the warning? [...] I would be in favor of doing that if it was wrapped in a macro. It would be good to have it explicitly obvious that we are casting away const\, so that we can have the compiler flag the ones we don't mean to cast away.
Me either. I searched the sources again and I found there had already been GCC_DIAG_IGNORE and GCC_DIAG_RESTORE macros for that.
The attached patch that replaces the third patch from the original patch set uses them to silence the warnings in utf8_hop functions.
Thanks\, applied the first two of the original patches and this new patch as 463ddf34c08f2c97199b1bb242da1f17494d4d1a\, 9f2eed981068e7abbcc52267863529bc59e9c8c0 and de97954862ed37d913c4b9a48758aba578a8cf0c.
Tony
@tonycoz - Status changed from 'open' to 'pending release'
Thank you for filing this report. You have helped make Perl better.
With the release today of Perl 5.26.0\, this and 210 other issues have been resolved.
Perl 5.26.0 may be downloaded via: https://metacpan.org/release/XSAWYERX/perl-5.26.0
If you find that the problem persists\, feel free to reopen this ticket.
@khwilliamson - Status changed from 'pending release' to 'resolved'
Migrated from rt.perl.org#130169 (status was 'resolved')
Searchable as RT130169$