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

--- Comment #2 from lavr at ncbi dot nlm.nih.gov ---
sja...@gcc.gnu.org:

Strictly speaking, returning a pointer is not the same as taking it in by
adding const qualifiers.  In my code example, "func()" can't change anything
pointed to by "str", and that's okay, even if the passed pointer was not const
in any way
(analogous to char* -> const char* in the function arguments, perfectly valid).

The return in your example creates a pointer alias to an object, which has now
been const'ed, on one hand, and yet, on the other hand, which can still be
modified through the original non-const pointer passed to that function.  Both
at the same level of the code nesting (the function caller).

My example does not do that;  it simply states that whatever memory areas
pointed to by "str" are not modifiable in "func()", and there's no aliasing
issue at all (which was merely why -Wincompatible-pointer-types was prompted to
an error in GCC14).

Reply via email to