throwing from (singleton) constructor gives segmentation fault

Bug #1051972 reported by aitors2005
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-defaults (Ubuntu)
Confirmed
Undecided
Unassigned

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 {
public:
  // Singleton
  static A & instance();

private:
  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.cc
% ./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)

Revision history for this message
aitors2005 (aitors2005) wrote :
Changed in gcc-defaults (Ubuntu):
status: New → Confirmed
Matthias Klose (doko)
summary: - throwing from (singleton) constructor gives segmentation fault
+ gcc doesn't isssue a strict aliasing warning on a code that seems to
+ break it
Matthias Klose (doko)
summary: - gcc doesn't isssue a strict aliasing warning on a code that seems to
- break it
+ throwing from (singleton) constructor gives segmentation fault
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.