From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23043 invoked by alias); 14 Apr 2009 16:54:14 -0000 Received: (qmail 23034 invoked by uid 22791); 14 Apr 2009 16:54:12 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.33.17) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Apr 2009 16:54:06 +0000 Received: from wpaz37.hot.corp.google.com (wpaz37.hot.corp.google.com [172.24.198.101]) by smtp-out.google.com with ESMTP id n3EGs3hD024358; Tue, 14 Apr 2009 17:54:03 +0100 Received: from localhost.localdomain.google.com (dhcp-172-22-125-203.mtv.corp.google.com [172.22.125.203]) (authenticated bits=0) by wpaz37.hot.corp.google.com with ESMTP id n3EGs06r013429 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Tue, 14 Apr 2009 09:54:01 -0700 To: Erik Cc: gcc-help@gcc.gnu.org Subject: Re: check that a member function really operates on an object of the expected type References: <49E4558C.3010307@gmail.com> <49E4BC11.9030202@gmail.com> From: Ian Lance Taylor Date: Tue, 14 Apr 2009 16:54:00 -0000 In-Reply-To: <49E4BC11.9030202@gmail.com> (Erik's message of "Tue\, 14 Apr 2009 18\:38\:41 +0200") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2009-04/txt/msg00152.txt.bz2 Erik writes: > Ian Lance Taylor skrev: >> Erik writes: >> >>> This will throw std::bad_cast if the bug in question is encountered. Of >>> course it is not practically possible to add such an assertion to the >>> beginning of every method, but there should be a compiler flag to enable >>> this (in debug builds). Is there such a flag? Is there a feature request >>> for it? >>> >> >> even if there were such a flag, it would not work reliably for your example. > > It must work reliably for my example (and it does). Perhaps I misunderstood your example. It seemed that your class was holding a reference to an object which had been passed to delete. If that is what was happening, then my statement is correct. If you are instead holding a reference to a partially but not completely destroyed object, then I agree that dynamic_cast can work correctly. However, I personally don't see a sufficient reason to add yet another compiler option to support an arguably broken programming style. Ian