This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/10138] warn for uninitialized arrays passed as const* arguments
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Aug 2007 14:56:25 -0000
- Subject: [Bug middle-end/10138] warn for uninitialized arrays passed as const* arguments
- References: <bug-10138-1038@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #11 from bangerth at dealii dot org 2007-08-20 14:56 -------
(In reply to comment #10)
> I now think that Andrew is right and that PR33086 and this one are INVALID.
> 'const' does not mean read-only in C++ at all, and much less in C. atoi(const
> char *) could always initialize buf[].
Uh, no, it can't. If it did (by casting away the 'const' from its argument
and then writing into the array), this would lead to a segfault:
-------------
const char a[3] = "10";
int main () {
return atoi (a);
}
-------------
The reason being that compilers will typically place 'a' into a read-only
memory section.
Passing an uninitialized object as a const reference or pointer is a bad
idea in C++ and should get a warning as a rule. I can't see reasons that would
warrant exceptions from this rule.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10138