public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Storsjö" <martin@martin.st>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] gcc: Make strchr return value pointers const
Date: Tue,  1 Sep 2020 16:01:42 +0300	[thread overview]
Message-ID: <20200901130142.6366-1-martin@martin.st> (raw)

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-01  Martin Storsjö  <martin@martin.st>

gcc/Changelog:
        * dwarf2out.c (file_name_acquire): Make a strchr return value
        pointer to const.

libcpp/Changelog:
        * files.c (remap_filename): Make a strchr return value pointer
        to const.
---
 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;
       }
-- 
2.17.1


             reply	other threads:[~2020-09-01 13:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-01 13:01 Martin Storsjö [this message]
2020-09-04  9:21 ` JonY
2020-09-04  9:32 ` Jakub Jelinek
2020-09-04 12:47   ` Martin Storsjö
2020-09-08  0:13     ` JonY
2020-09-08 11:16       ` Richard Sandiford
2020-09-08 11:50         ` Jakub Jelinek
2020-09-08 12:03           ` Martin Storsjö
2020-09-17  3:56       ` Jeff Law
2020-09-17  6:19         ` JonY

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200901130142.6366-1-martin@martin.st \
    --to=martin@martin.st \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).