From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31422 invoked by alias); 10 Apr 2012 04:43:15 -0000 Received: (qmail 31405 invoked by uid 22791); 10 Apr 2012 04:43:12 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-pz0-f49.google.com (HELO mail-pz0-f49.google.com) (209.85.210.49) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Apr 2012 04:42:59 +0000 Received: by dadq36 with SMTP id q36so5893419dad.22 for ; Mon, 09 Apr 2012 21:42:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:x-gm-message-state; bh=XsdSAvjBbLYz/YcAiMLUNs/WZUJr3rzBJFylFPyHviU=; b=CkJIYJH8iyIdC0Vl5xihpiBVgN+ExUMORmBp1JI2ODKYZFOnaBzP83LS/DG/rwLpXE Q8Jl02ObOUVVyc5J9K6XUXEx29daTpLvYI8ALiHEmmSurvxF5F+X3bgX4dED+VriWES1 6AUxMIJgfdujytkbSawKKtEjdaO835pEExABb+m5WZI2fco3oeUmoD1/qxqx3qK6bK/i E7xM1Keb9CPVWaCucNkQsOhmHI9SqbcntNISFfCDN1HdmQEI7rxPeIa311Yw72lmRzN/ nED8uwCzJn5eaohDXh+FBix6bEGbUT4SeSn7jj6nkA5tVQQ/xZeRUlR4IkhysLmS1e+P /0yw== Received: by 10.68.211.36 with SMTP id mz4mr13123542pbc.150.1334032979339; Mon, 09 Apr 2012 21:42:59 -0700 (PDT) Received: by 10.68.211.36 with SMTP id mz4mr13123529pbc.150.1334032979242; Mon, 09 Apr 2012 21:42:59 -0700 (PDT) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id w10sm16839122pbk.30.2012.04.09.21.42.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 Apr 2012 21:42:58 -0700 (PDT) From: Ian Lance Taylor To: "sarah\@hederstierna.com" Cc: "gcc\@gcc.gnu.org" Subject: Re: Warn if making external references to local stack memory? References: Date: Tue, 10 Apr 2012 04:43:00 -0000 In-Reply-To: (fredrik@hederstierna.com's message of "Mon, 9 Apr 2012 07:54:55 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQmydW//E07hqoFD/PcfxG/rt1zmlfM1ZW6ajBZeUYP4oPem9IipoTcXU69TPR5XUB8VekinGjrQo5iavRJIO3bL83b3MGfYaN6Np4BHw1PeH4Yzrt/AXk1UOqCaHIuk/iQU7X7gQGToa2v+kOhB7OZrg5Cu5w== X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg00298.txt.bz2 "sarah@hederstierna.com" writes: > GCC does warn if returning a pointer to a local variable (stack memory). > But there are alot of more cases where GCC could possibly warn, > eg. when references are made to local variables or stack memory. > > See this attached example code. > GCC warns for first case, but not the others. > I think all cases can be considered program bugs, > and could trigger a compiler warning I think. Thanks. I would encourage you to file an enhancement request at http://gcc.gnu.org/bugzilla/ . > I've found out that the present warning is done in "c-typeck.c", > is this the right place to but additional warnings of this kind too? Since these sorts of errors can occur in both C and C++ it would be slightly better to use a common framework for them if possible, perhaps in c-family/c-common.c. I haven't really thought about what is required here, though. Ian