[libvirt] [PATCH] build: silence a clang warning in virsh.c

This patch shuts up the following warning of clang: virsh.c:2761:22: error: assigning to 'char *' from 'const char [6]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] rl_readline_name = "virsh"; ^ ~~~~~~~ Tested on Mac OS X 10.8.5 (clang-500.2.75) and Fedora 19 (gcc 4.8.1). Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com> --- tools/virsh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/virsh.c b/tools/virsh.c index 241c5b8..f45ee0a 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2758,7 +2758,7 @@ vshReadlineInit(vshControl *ctl) const char *histsize_str; /* Allow conditional parsing of the ~/.inputrc file. */ - rl_readline_name = "virsh"; + rl_readline_name = (char *) "virsh"; /* Tell the completer that we want a crack first. */ rl_attempted_completion_function = vshReadlineCompletion; -- 1.8.4

On 11/04/2013 03:49 AM, Ryota Ozaki wrote:
This patch shuts up the following warning of clang:
virsh.c:2761:22: error: assigning to 'char *' from 'const char [6]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] rl_readline_name = "virsh"; ^ ~~~~~~~
Huh? <readline/readline.h> lists: /* The name of the calling program. You should initialize this to whatever was in argv[0]. It is used when parsing conditionals. */ extern const char *rl_readline_name; at least for readline-devel-6.2 on Fedora 19. Why is clang failing to see that the assignment is to something already marked const? Is it a bug in your readline header?
Tested on Mac OS X 10.8.5 (clang-500.2.75) and Fedora 19 (gcc 4.8.1).
Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com> --- tools/virsh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/virsh.c b/tools/virsh.c index 241c5b8..f45ee0a 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2758,7 +2758,7 @@ vshReadlineInit(vshControl *ctl) const char *histsize_str;
/* Allow conditional parsing of the ~/.inputrc file. */ - rl_readline_name = "virsh"; + rl_readline_name = (char *) "virsh";
On the surface, this seems okay, but I'd rather know WHY we need it, and also add a comment that casting away const is due to whatever the root cause is. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Tue, Nov 5, 2013 at 1:08 AM, Eric Blake <eblake@redhat.com> wrote:
On 11/04/2013 03:49 AM, Ryota Ozaki wrote:
This patch shuts up the following warning of clang:
virsh.c:2761:22: error: assigning to 'char *' from 'const char [6]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] rl_readline_name = "virsh"; ^ ~~~~~~~
Huh? <readline/readline.h> lists:
/* The name of the calling program. You should initialize this to whatever was in argv[0]. It is used when parsing conditionals. */ extern const char *rl_readline_name;
at least for readline-devel-6.2 on Fedora 19. Why is clang failing to see that the assignment is to something already marked const? Is it a bug in your readline header?
Grrr. It seems that this is Mac OS X specific problem :-/ /usr/include/readline/readline.h of Mac OS X is still: extern char *rl_readline_name; The readline.h seems to be checked out from an old NetBSD and not updated for a long time. BTW recent *BSD seem to have migrated to the above const char * version.
Tested on Mac OS X 10.8.5 (clang-500.2.75) and Fedora 19 (gcc 4.8.1).
Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com> --- tools/virsh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/virsh.c b/tools/virsh.c index 241c5b8..f45ee0a 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2758,7 +2758,7 @@ vshReadlineInit(vshControl *ctl) const char *histsize_str;
/* Allow conditional parsing of the ~/.inputrc file. */ - rl_readline_name = "virsh"; + rl_readline_name = (char *) "virsh";
On the surface, this seems okay, but I'd rather know WHY we need it, and also add a comment that casting away const is due to whatever the root cause is.
So we need to write a comment about the Mac OS X's flaw. I'll send a revised patch later. Thanks, ozaki-r
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Mon, Nov 4, 2013 at 12:26 PM, Ryota Ozaki <ozaki.ryota@gmail.com> wrote:
On Tue, Nov 5, 2013 at 1:08 AM, Eric Blake <eblake@redhat.com> wrote:
On 11/04/2013 03:49 AM, Ryota Ozaki wrote:
This patch shuts up the following warning of clang:
virsh.c:2761:22: error: assigning to 'char *' from 'const char [6]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] rl_readline_name = "virsh"; ^ ~~~~~~~
Huh? <readline/readline.h> lists:
/* The name of the calling program. You should initialize this to whatever was in argv[0]. It is used when parsing conditionals. */ extern const char *rl_readline_name;
at least for readline-devel-6.2 on Fedora 19. Why is clang failing to see that the assignment is to something already marked const? Is it a bug in your readline header?
Grrr. It seems that this is Mac OS X specific problem :-/ /usr/include/readline/readline.h of Mac OS X is still: extern char *rl_readline_name;
The readline.h seems to be checked out from an old NetBSD and not updated for a long time.
BTW recent *BSD seem to have migrated to the above const char * version.
We likely should forward a note on to Apple about that. -- Doug Goldstein

On Tue, Nov 5, 2013 at 3:58 AM, Doug Goldstein <cardoe@gentoo.org> wrote:
On Mon, Nov 4, 2013 at 12:26 PM, Ryota Ozaki <ozaki.ryota@gmail.com> wrote:
On Tue, Nov 5, 2013 at 1:08 AM, Eric Blake <eblake@redhat.com> wrote:
On 11/04/2013 03:49 AM, Ryota Ozaki wrote:
This patch shuts up the following warning of clang:
virsh.c:2761:22: error: assigning to 'char *' from 'const char [6]' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers] rl_readline_name = "virsh"; ^ ~~~~~~~
Huh? <readline/readline.h> lists:
/* The name of the calling program. You should initialize this to whatever was in argv[0]. It is used when parsing conditionals. */ extern const char *rl_readline_name;
at least for readline-devel-6.2 on Fedora 19. Why is clang failing to see that the assignment is to something already marked const? Is it a bug in your readline header?
Grrr. It seems that this is Mac OS X specific problem :-/ /usr/include/readline/readline.h of Mac OS X is still: extern char *rl_readline_name;
The readline.h seems to be checked out from an old NetBSD and not updated for a long time.
BTW recent *BSD seem to have migrated to the above const char * version.
We likely should forward a note on to Apple about that.
# I'm sorry for late replying. Yah, I will ask them about this (and rpcgen). And also I'm sending a new patch with additional comments about this matter. Thanks, ozaki-r
-- Doug Goldstein
participants (3)
-
Doug Goldstein
-
Eric Blake
-
Ryota Ozaki