[gcc r11-3030] gcc: Make strchr return value pointers const

Jakub Jelinek jakub@gcc.gnu.org
Mon Sep 7 11:20:41 GMT 2020


https://gcc.gnu.org/g:3fe3efe5c141a88a80c1ecc6aebc7f15d6426f62

commit r11-3030-g3fe3efe5c141a88a80c1ecc6aebc7f15d6426f62
Author: Martin Storsjö <martin@martin.st>
Date:   Mon Sep 7 13:18:42 2020 +0200

    gcc: Make strchr return value pointers const
    
    This fixes compilation of codepaths for dos-like filesystems
    with Clang. When built with clang, it treats C input files as C++
    when the compiler driver is invoked in C++ mode, triggering errors
    when the return value of strchr() on a pointer to const is assigned
    to a pointer to non-const variable.
    
    This matches similar variables outside of the ifdefs for dos-like
    path handling.
    
    2020-09-07  Martin Storsjö  <martin@martin.st>
    
    gcc/
            * dwarf2out.c (file_name_acquire): Make a strchr return value
            pointer to const.
    libcpp/
            * files.c (remap_filename): Make a strchr return value pointer
            to const.

Diff:
---
 gcc/dwarf2out.c | 2 +-
 libcpp/files.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index b6ab49bb548..4096c0c0d69 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -12118,7 +12118,7 @@ file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad)
   f = strrchr (f, DIR_SEPARATOR);
 #if defined (DIR_SEPARATOR_2)
   {
-    char *g = strrchr (fi->path, DIR_SEPARATOR_2);
+    const char *g = strrchr (fi->path, DIR_SEPARATOR_2);
 
     if (g != NULL)
       {
diff --git a/libcpp/files.c b/libcpp/files.c
index 3d48c38fc0a..b890b8ebf1e 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -1693,7 +1693,7 @@ remap_filename (cpp_reader *pfile, _cpp_file *file)
       p = strchr (fname, '/');
 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
       {
-	char *p2 = strchr (fname, '\\');
+	const char *p2 = strchr (fname, '\\');
 	if (!p || (p > p2))
 	  p = p2;
       }


More information about the Gcc-cvs mailing list