zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: "Jörg Sommer" <joerg@jo-so.de>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH 2/6] lex: Mark variables with const init as const
Date: Fri, 26 Jan 2024 08:39:49 +0100	[thread overview]
Message-ID: <2942-1706254789.333425@NzBz.rL2-.PsQC> (raw)
In-Reply-To: <da1d39281afe608b6567af7e499af74df428c1ed.1704132620.git.joerg@jo-so.de>

On 1 Jan, Jörg Sommer wrote:
> Because these variables are initialized with as constant string, they should
> be marked as *const* to make the compiler running with `-Wwrite-strings`
> more happy.

Applying this patch series causes a couple of fresh warnings:

zle_thingy.c: In function 'bin_zle_refresh':
zle_thingy.c:420:15: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  420 |     char *s = statusline;
      |

lex.c: In function 'exalias':
lex.c:1964:20: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
 1964 |         zshlextext = tokstrings[tok];
      |

clang describes these as "initializing 'char *' with an expression of
type 'const char *' discards qualifiers
[-Wincompatible-pointer-types-discards-qualifiers]".

I have no objection to adding const in more places where possible. You
may find we have code that is not really modifying its parameter but
relies on being able to temporarily swap a nul in for a character as
part of parsing. I also tend to find the old issue that you can't
safely cast a char ** to const char** tends to get in the way.

Oliver


  reply	other threads:[~2024-01-26  7:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-01 18:10 Extend usage of const char* Jörg Sommer
2024-01-01 18:10 ` [PATCH 1/6] zle.textobjects: Mark variables as const Jörg Sommer
2024-01-01 18:10   ` [PATCH 2/6] lex: Mark variables with const init " Jörg Sommer
2024-01-26  7:39     ` Oliver Kiddle [this message]
2024-01-27  6:41       ` Jörg Sommer
2024-01-28  0:18         ` Oliver Kiddle
2024-01-01 18:10   ` [PATCH 3/6] zle_vi: " Jörg Sommer
2024-01-01 18:10   ` [PATCH 4/6] zle_main: mark statusline " Jörg Sommer
2024-01-01 18:10   ` [PATCH 5/6] module: Mark name argument of some functions const Jörg Sommer
2024-01-01 18:10   ` [PATCH 6/6] zsh: mark hookdef.name as const Jörg Sommer

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=2942-1706254789.333425@NzBz.rL2-.PsQC \
    --to=opk@zsh.org \
    --cc=joerg@jo-so.de \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).