This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Silent const correctnes warnings in utf8_hop functions
authorPetr Písař <ppisar@redhat.com>
Mon, 28 Nov 2016 12:06:24 +0000 (13:06 +0100)
committerTony Cook <tony@develop-help.com>
Wed, 30 Nov 2016 23:13:30 +0000 (10:13 +1100)
GCC -Wcast-qual option reports a const violation in utf8_hop
functions. They take a pointer to constant data but returns pointer to
non-constant data.

It's impossible to fix this without changing their prototype.
Therefore this patch asks a compiler to ignore the violations.

Signed-off-by: Petr Písař <ppisar@redhat.com>
inline.h

index 346dcdc..acd19e5 100644 (file)
--- a/inline.h
+++ b/inline.h
@@ -916,7 +916,9 @@ Perl_utf8_hop(const U8 *s, SSize_t off)
                s--;
        }
     }
+    GCC_DIAG_IGNORE(-Wcast-qual);
     return (U8 *)s;
+    GCC_DIAG_RESTORE;
 }
 
 /*
@@ -950,12 +952,17 @@ Perl_utf8_hop_forward(const U8 *s, SSize_t off, const U8 *end)
 
     while (off--) {
         STRLEN skip = UTF8SKIP(s);
-        if ((STRLEN)(end - s) <= skip)
+        if ((STRLEN)(end - s) <= skip) {
+            GCC_DIAG_IGNORE(-Wcast-qual);
             return (U8 *)end;
+            GCC_DIAG_RESTORE;
+        }
         s += skip;
     }
 
+    GCC_DIAG_IGNORE(-Wcast-qual);
     return (U8 *)s;
+    GCC_DIAG_RESTORE;
 }
 
 /*
@@ -993,7 +1000,9 @@ Perl_utf8_hop_back(const U8 *s, SSize_t off, const U8 *start)
             s--;
     }
     
+    GCC_DIAG_IGNORE(-Wcast-qual);
     return (U8 *)s;
+    GCC_DIAG_RESTORE;
 }
 
 /*