mailing list of musl libc
 help / color / mirror / code / Atom feed
* syslog.h prioritynames define not compatible with -Wwrite-strings
@ 2016-08-25  7:47 Per Johansson
  2016-08-30 21:20 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Per Johansson @ 2016-08-25  7:47 UTC (permalink / raw)
  To: musl

Hello,

I'm trying to port a code base to musl. I've run into an issue with
prioritynames as defined by syslog.h:

CODE *pri_code = prioritynames;

produces

error: initialization discards 'const' qualifier from pointer target
type [-Werror=discarded-qualifiers]

This is repeated once per element in the array.

While the error message points to -Wdiscarded-qualifiers I believe
this is actually due to us using -Wwrite-strings which turns string
literals into type const char* instead of char*.

I suppose the most compatible solution would be to cast each string
literal to char* in the define. It's either that or use const char* in
the struct, but that's likely to cause issues in other programs.
Or use some trickery to disable the warning I suppose, wouldn't know about that.

Please CC me on any reply as I'm currently not subscribed.

Minimal code to reproduce:

#define SYSLOG_NAMES
#include <syslog.h>
CODE *c = prioritynames;

Compiles without warning:
gcc -nostdinc -isystem include -isystem obj/include -c test.c

Adding -Wwrite-strings give warnings:
gcc -Wwrite-strings -nostdinc -isystem include -isystem obj/include -c test.c

Regards,
-- 
Per Johansson


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: syslog.h prioritynames define not compatible with -Wwrite-strings
  2016-08-25  7:47 syslog.h prioritynames define not compatible with -Wwrite-strings Per Johansson
@ 2016-08-30 21:20 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2016-08-30 21:20 UTC (permalink / raw)
  To: Per Johansson; +Cc: musl

On Thu, Aug 25, 2016 at 09:47:06AM +0200, Per Johansson wrote:
> Hello,
> 
> I'm trying to port a code base to musl. I've run into an issue with
> prioritynames as defined by syslog.h:
> 
> CODE *pri_code = prioritynames;
> 
> produces
> 
> error: initialization discards 'const' qualifier from pointer target
> type [-Werror=discarded-qualifiers]
> 
> This is repeated once per element in the array.
> 
> While the error message points to -Wdiscarded-qualifiers I believe
> this is actually due to us using -Wwrite-strings which turns string
> literals into type const char* instead of char*.

This is a nasty problem with how -Wwrite-strings is implemented. It
does not act as a warning option but fundamentally changes the
languages semantics in a way that is not C. I have an open bug report
against gcc for this:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61579

> I suppose the most compatible solution would be to cast each string
> literal to char* in the define. It's either that or use const char* in
> the struct, but that's likely to cause issues in other programs.
> Or use some trickery to disable the warning I suppose, wouldn't know about that.
> 
> Please CC me on any reply as I'm currently not subscribed.
> 
> Minimal code to reproduce:
> 
> #define SYSLOG_NAMES
> #include <syslog.h>
> CODE *c = prioritynames;
> 
> Compiles without warning:
> gcc -nostdinc -isystem include -isystem obj/include -c test.c
> 
> Adding -Wwrite-strings give warnings:
> gcc -Wwrite-strings -nostdinc -isystem include -isystem obj/include -c test.c

Based on the above, I don't consider this a bug in musl but a bug in
gcc's -Wwrite-strings. However, there are a lot of other problems
created by the current implementation of the SYSLOG_NAMES stuff, and
it needs to be redone entirely, probably more closely matching how
legacy implementations did it (the SYSLOG_NAMES stuff is all legacy
cruft anyway and shouldn't be used in modern code).

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-30 21:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-25  7:47 syslog.h prioritynames define not compatible with -Wwrite-strings Per Johansson
2016-08-30 21:20 ` Rich Felker

Code repositories for project(s) associated with this public inbox

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

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).