[Bug c++/58822] Segfault when calling make_shared

vlukas at gmx dot de gcc-bugzilla@gcc.gnu.org
Tue Nov 12 23:11:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58822

vlukas at gmx dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vlukas at gmx dot de

--- Comment #26 from vlukas at gmx dot de ---
I think the main.ii from 2013-10-23 can be reduced to this:
-----------------------------------------------------------
struct Exception {
  Exception(int) {}
};

template<typename Arg>
int make_shared(Arg arg)
{
  Exception* p = arg; p = p;
  return 0;
}

struct InvalidArgumentException : public virtual Exception
{
 explicit InvalidArgumentException() : Exception(make_shared(this))
 { }

  virtual ~InvalidArgumentException() noexcept {}
};

int main()
{
  throw InvalidArgumentException();
}
----------------------------------------------------------

I believe this violates a restriction of the Standard, namely section 3.8,
paragraph 5, dash 3 (in the N3290 draft or in N3797).

I can reproduce a segmentation fault with both my reduced testcase and the
original main.ii.

Mr. Henning, you could try the following:
In your main.ii on line 24571 substitute the *implicit* cast by an explicit
one, so that the line reads
: Exception(std::make_shared<ExceptionImplBase>(static_cast<Exception*>(this)))

Or replace the forbidden implicit cast by changing line 24556 so that it reads
template<class E> explicit ExceptionImplBase(E const*) {}

Both options fulfill the requirements of the Standard to the letter and on my
system make the segmentation fault go away. Valgrind won't indicated an error
with those modifications either.



More information about the Gcc-bugs mailing list