From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16792 invoked by alias); 20 Aug 2007 15:54:27 -0000 Received: (qmail 15081 invoked by uid 48); 20 Aug 2007 15:54:16 -0000 Date: Mon, 20 Aug 2007 15:54:00 -0000 Message-ID: <20070820155416.15080.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug middle-end/10138] warn for uninitialized arrays passed as const* arguments In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "bangerth at dealii dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-08/txt/msg01401.txt.bz2 ------- Comment #14 from bangerth at dealii dot org 2007-08-20 15:54 ------- (In reply to comment #12) > This testcase has nothing to do with uninitialized variables. No, of course. I only meant to reply to your assertion that there could be cases where a function initializes an object that is passed as a const pointer. That may work in C, but not in C++. I agree that my example may have been confusing, so take this slight variant of it ('a' is here non-const and uninitialized): ------------------- char a[3]; int main () { return atoi (a); } ------------------- It is my understanding that C++ allows 'a' to be put into read-only memory because the only access is read-only. What that means is that functions like atoi that take constant arguments have no legitimate way to initialize the objects they get, and every uninitialized object passed to them is necessarily a source of bugs. This is meant to only counter your point that: > 'const' does not mean read-only in C++ at all, and much less in C. atoi(const > char *) could always initialize buf[]. This simply isn't true. In C++, atoi can't do that. W. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10138