Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: dbaf52f602f7474231460fe8930b3c5564df10c5
      
https://github.com/Perl/perl5/commit/dbaf52f602f7474231460fe8930b3c5564df10c5
  Author: Tony Cook <t...@develop-help.com>
  Date:   2024-06-18 (Tue, 18 Jun 2024)

  Changed paths:
    M inline.h

  Log Message:
  -----------
  my_strnlen(): eliminate unneeded casting away of const

Noticed this while reviewing #22271.

If you build with:

  ./Configure -des -Dusedevel -Ud_strnlen -Accflags=-Wcast-qual -Dcc=g++

you will see amongst many other warnings:

inline.h: In function ‘size_t Perl_my_strnlen(const char*, size_t)’:
inline.h:4220:23: warning: cast from type ‘const void*’ to type ‘char*’ casts 
away qualifiers [-Wcast-qual]
 4220 |     const char *end = (char *) memchr(str, '\0', maxlen);
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The cast itself is only needed on C++ to cast from "const void *", C
doesn't require any cast here.


  Commit: ca81be37067e1358d98f77b8f7df53cc22a554b6
      
https://github.com/Perl/perl5/commit/ca81be37067e1358d98f77b8f7df53cc22a554b6
  Author: Tony Cook <t...@develop-help.com>
  Date:   2024-06-18 (Tue, 18 Jun 2024)

  Changed paths:
    M utf8.h

  Log Message:
  -----------
  UTF8_CHK_SKIP: eliminate casting away const

Seen with:

  ./Configure -des -Dusedevel -Accflags=-Wcast-qual

mathoms.c: In function ‘Perl_utf8_to_uvchr’:
utf8.h:804:53: warning: cast discards ‘const’ qualifier from pointer target type
 [-Wcast-qual]
  804 |            (UNLIKELY(s[0] == '\0') ? 1 : my_strnlen((char *) (s), UTF8SK
IP(s)))
      |                                                     ^
embed.h:792:87: note: in definition of macro ‘utf8_to_uvchr_buf_helper’
  792 | # define utf8_to_uvchr_buf_helper(a,b,c)        Perl_utf8_to_uvchr_buf_h
elper(aTHX_ a,b,c)
      |
              ^
mathoms.c:970:12: note: in expansion of macro ‘utf8_to_uvchr_buf’
  970 |     return utf8_to_uvchr_buf(s, s + UTF8_CHK_SKIP(s), retlen);
      |            ^~~~~~~~~~~~~~~~~
mathoms.c:970:37: note: in expansion of macro ‘UTF8_CHK_SKIP’
  970 |     return utf8_to_uvchr_buf(s, s + UTF8_CHK_SKIP(s), retlen);
      |                                     ^~~~~~~~~~~~~

mathoms.c seems to be the only user of this macro.

This came up when reviewing #22271


Compare: https://github.com/Perl/perl5/compare/6c1a9be7c8b2...ca81be37067e

To unsubscribe from these emails, change your notification settings at 
https://github.com/Perl/perl5/settings/notifications

Reply via email to