[Bug 1051972] Re: throwing from (singleton) constructor gives segmentation fault

aitors2005 aitors2005 at gmail.com
Mon Sep 17 13:44:07 UTC 2012

You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-defaults in Ubuntu.

  throwing from (singleton) constructor gives segmentation fault

Status in “gcc-defaults” package in 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.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)

To manage notifications about this bug go to:

More information about the foundations-bugs mailing list