throwing from (singleton) constructor gives segmentation fault

Bug #1051972 reported by aitors2005 on 2012-09-17
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-defaults (Ubuntu)

Bug Description

Hi, the following program gets a segmentation fault. It works OK on another machine (g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52)).

#include <iostream>
#include <string>
#include <stdexcept>

using namespace std;

class A {
  // Singleton
  static A & instance();

  A() {
 throw std::runtime_error("throw\n");


A & A::instance() {
  static A inst;
  return inst;

int main () {

  const A & a = A::instance();

  return 0;

% g++ -o foo
% ./foo
terminate called after throwing an instance of 'std::runtime_error'
  what(): throw

Aborted (core dumped)

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: g++ 4:4.6.3-1ubuntu5
ProcVersionSignature: Ubuntu 3.2.0-27.43-generic-pae 3.2.21
Uname: Linux 3.2.0-27-generic-pae i686
NonfreeKernelModules: nvidia
ApportVersion: 2.0.1-0ubuntu13
Architecture: i386
Date: Mon Sep 17 15:39:58 2012
InstallationMedia: Ubuntu 9.10 "Karmic Koala" - Release i386 (20091028.5)
SourcePackage: gcc-defaults
UpgradeStatus: Upgraded to precise on 2012-06-06 (103 days ago)

aitors2005 (aitors2005) wrote :
Changed in gcc-defaults (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers