This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH,c++] use XALLOCAVEC in the C++ front-end
On 8 June 2010 18:14, Jason Merrill <jason@redhat.com> wrote:
> On 06/08/2010 10:43 AM, Manuel López-Ibáñez wrote:
>>
>> On 8 June 2010 16:06, Jason Merrill<jason@redhat.com> ?wrote:
>
>>> The error message is unclear, but the issue is that converting from
>>> char**
>>> to char const** is unsafe, while converting to char const*const* is safe.
>>
>> What does it mean unsafe in this context? I could produce a patch that
>> changes the message but I would like to be sure what to say.
>>
>> semantics.c:1223:7: error: new ‘const’ qualifier in cast from 'char
>> **' to 'const char **' is unsafe [-Werror=cast-qual]
> Explanation from the C++ standard (4.4 [conv.qual]):
>
> [ Note: if a program could assign a pointer of type T** to a pointer of type
> const T** (that is, if line #1 below were allowed), a program could
> inadvertently modify a const object (as it is done on line #2). For example,
>
> ?int main() {
> ? ?const char c = ’c’;
> ? ?char* pc;
> ? ?const char** pcc = &pc;// #1: not allowed
> ? ?*pcc = &c;
> ? ?*pc = ’C’; // #2: modifies a const object
> ?}
> --end note ]
So what do you think about the following message:
error: new ‘const’ qualifier in cast from 'char **' to 'const char **'
is unsafe [-Werror=cast-qual]
note: to be safe all intermediate pointers must be equally qualified
Cheers,
Manuel.