From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26075 invoked by alias); 7 Feb 2006 00:26:11 -0000 Received: (qmail 26061 invoked by uid 48); 7 Feb 2006 00:26:08 -0000 Date: Tue, 07 Feb 2006 00:26:00 -0000 Subject: [Bug c++/26143] New: [4.0 Regression] wrong code when returning a function pointer X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "halcy0n at gentoo dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2006-02/txt/msg00588.txt.bz2 List-Id: The following testcase causes a segfault when compiled with 4.0.3 20060206 (with no optimizations). gcc-3.3, 3.4, and 4.1 all seem to work fine with this code. --------- #include std::string exception_to_debug_string(const std::exception & e) { return std::string("hey now"); } class DebugStringHolder { public: std::string (*get()) (const std::exception &) const { return &exception_to_debug_string; } }; static DebugStringHolder _instance; int main(int, char * argv[]) { try { throw std::exception(); } catch (std::exception &e) { std::cout << (_instance.get())(e) << std::endl; } } Results with 4.0: halcyon@birdbath ~ $ ./a.out *** glibc detected *** free(): invalid pointer: 0xb7e6cfe8 *** Aborted Results with 4.1: halcyon@birdbath ~ $ ./a.out hey now On 4.1 it seems it was fixed by pr #19317 -- Summary: [4.0 Regression] wrong code when returning a function pointer Product: gcc Version: 4.0.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: halcy0n at gentoo dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26143