[Bug 221533] New: strstr/c23/constness

[email protected]
Newsgroups org.kernel.vger.linux-man
Message-ID <[email protected]/>
https://bugzilla.kernel.org/show_bug.cgi?id=221533

            Bug ID: 221533
           Summary: strstr/c23/constness
           Product: Documentation
           Version: unspecified
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P3
         Component: man-pages
          Assignee: [email protected]
          Reporter: [email protected]
        Regression: No

Hi,
  In C23 strstr can return a const char* if the first parameter is a const
char*;  this is also true of a bunch of the other routines.

  I'm not really sure how this should be documented, I guess two entries for
each function with some note saying it's only C23 and later?

See:
https://sourceware.org/cgit/glibc/commit/string/string.h?id=cd748a63ab1a7ae846175c532a3daab341c62690

for the glibc change that implemented it.

It can break some existing code, e.g. something like:


int foo(const char *a)
{
   char *bar = strstr(a, "frog");
}

gives:
t.c:9:16: warning: initialization discards ‘const’ qualifier from pointer
target type [-Wdiscarded-qualifiers]
    9 |    char *bar = strstr(a, "frog");
      |                ^~~~~~

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.