Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7500059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:03:02+00:00 2026-05-29T20:03:02+00:00

Using gcc 4.6.2, make_shared() gives a useless backtrace (apparently due to some rethrow) if

  • 0

Using gcc 4.6.2, make_shared() gives a useless backtrace (apparently due to some rethrow) if a constructor throws an exception. I’m using make_shared() to save a bit of typing, but this is show stopper. I’ve created a substitute make_shrd() that allows a normal backtrace. I’m using gdb 7.3.1.

I’m worried that:

  1. The bad backtrace under make_shared() is somehow my own fault
  2. My substitute make_shrd() will cause me subtle problems.

Here’s a demo:

#include <memory>
#include <stdexcept>

using namespace std;

class foo1
{
public:
        foo1( const string& bar, int x ) :m_bar(bar), m_x(x)
        {
                throw logic_error( "Huh?" );
        }
        string m_bar;
        int m_x;
};

class foo2
{
public:
        foo2( const string& bar, int x ) : m_foo1(bar,x)
        {}

        foo1  m_foo1;
};

// more debuggable substitute for make_shared() ??
template<typename T, typename... Args>
std::shared_ptr<T> make_shrd( Args... args )
{
        return std::shared_ptr<T>( new T(args...));
}

int main()
{
        auto p_foo2 = make_shared<foo2>( "stuff", 5 );          // debug BAD!!
//      auto p_foo2 = make_shrd<foo2>( "stuff", 5 );            // debug OK
//      auto p_foo2 = new foo2( "stuff", 5 );                   // debug OK
//      auto p_foo2 = shared_ptr<foo2>(new foo2( "stuff", 5 )); // debug OK
        return (int)(long int)p_foo2;
}

Compiled with:

g++ -g -std=c++0x -Wall -Wextra main.cpp

Debugged with:

gdb a.out

The make_shared() backtrace is junk that does not show the stack to the point of the exception. All the other options provide a sane backtrace.

Thanks in advance for help and suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:03:03+00:00Added an answer on May 29, 2026 at 8:03 pm

    Your implementation of make_shrd() looses the ability to allocate just one chunk of memory: std::make_shared() does two things:

    1. it avoids duplicating of writing the type (if the type of the allocation and the type of the desired std::shared_ptr<T> are the same rather than the latter being for a base class)
    2. it combines allocation of the shared object and the object’s descriptor into just one allocation

    The main purpose of std::make_shared() is actually the second feature. I haven’t looked at the implementation but I suspect that this is also the part which actually causes you problems. Other than that, I don’t see any reason why your implementation is any worse once you fix forwarding of arguments:

    template<typename T, typename... Args>
    std::shared_ptr<T> make_shrd(Args&&... args)
    {
        return std::shared_ptr<T>(new T(std::forward<Args>(args)...));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using GCC 4.3.3 on Ubuntu 9.04 64-bit and was getting errors using C++-style
I'm using gcc, which implements enums as 32 bit integers on the architecture I
GCC compiles (using gcc --omit-frame-pointer -s ): int the_answer() { return 42; } into
I am using gcc for windows . The OS is windows XP . How
I'm using GCC to generate a dependency file, but my build rules put the
I'm using GCC; __FILE__ returns the current source file's entire path and name: /path/to/file.cpp
I'm temporarily using gcc 2.95.2, and instead of having a sstream header, it defines
I am using gcc -MM to generate prerequisites of dependencies rules for compiling source
I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE>
I am using gcc/g++ to compile c/c++ applications - living on OpenSuSe btw. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.