[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-zile] astr_cstr
From: |
Reuben Thomas |
Subject: |
[Bug-zile] astr_cstr |
Date: |
Wed, 7 Sep 2011 12:44:02 +0100 |
Re. a recent commit:
commit 5171aa758f7354e8db522f341a2dc55563e82a62
Author: Gary V. Vaughan <address@hidden>
Date: Thu Sep 1 21:57:27 2011 +0700
compiler warning: assignment to as->text discards const
remove the constness of the string passed to castr_new_nstr, because
once its address is held in as->text, the rest of the code will not
treat it as const anyway; thus, we also have to remove the constness of
return type of astr_cstr() which is simply giving the address in the
non-const as->text pointer too.
I am unhappy with this, because it removes compiler warnings about two
sorts of potential bug:
1. Code overwrites the return value of astr_cstr and the compiler
doesn't complain. (astr_cstr returns a read-only copy of an astr as a
char *; it's pure coincidence that it happens to be the actual
representation too.)
2. Code passes a non-const string to castr_new_nstr. The whole point
of this constructor is that the string really is const! (Look at the
code for castr_new_nstr). The underlying problem here is trying to
have two structured types, astr and castr, which are compatible but
one of which is immutable.
This is a good example of where trying to keep the compiler happy
actually makes things worse (and why the GCS does not insist on
warning-free compilation, even with the GNU compiler).
--
http://rrt.sc3d.org
- [Bug-zile] astr_cstr,
Reuben Thomas <=