<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Virtual Inheritance Access Violation - Fehler oder nicht?]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich kämpfe gerade mit einem Problem in Visual C++; mit LLVM und GCC tritt der Fehler nicht auf. Und zwar geht es um virtuelle Vererbung. Gegeben sei folgendes, eingedummtes Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

#define where_am_i std::cout &lt;&lt; __FUNCTION__ &lt;&lt; std::endl;

namespace test
{

    class disp_base
    {
    public:
        disp_base()
        {
            where_am_i
        }
        virtual ~disp_base()
        {
            where_am_i
        }
    };

    class disp : public virtual disp_base
    {
    public:
        disp()
        {
            where_am_i
        }
        virtual ~disp()
        {
            where_am_i
        }
    };

    class refl : public virtual disp_base
    {
    public:
        refl()
        {
            where_am_i
        }
        virtual ~refl()
        {
            where_am_i
        }
    };

    class foo : public virtual disp, public refl
    {
        void *something;
    public:
        foo() : foo(static_cast&lt;void *&gt;(this))
        {
            where_am_i
        }
        foo(void *test) : something(test)
        {
            where_am_i
        }
        virtual ~foo()
        {
            where_am_i
        }
    };

    class bar : public virtual foo
    {
    public:
        bar()
        {
            where_am_i
        }
        virtual ~bar()
        {
            where_am_i
        }
    };

}

int main()
{
    test::bar fail;
}
</code></pre>
<p>Mit GCC-4.9.2 erhalte ich folgenden Output:</p>
<pre><code>disp_base
disp
refl
foo
foo
bar
~bar
~foo
~refl
~disp
~disp_base
</code></pre>
<p>Auch LLVM frisst den Code problemlos. Mit Visual C++ 2013 hingegen erhalte ich folgendes:</p>
<pre><code>disp_base
disp
disp_base
disp
refl
foo
foo
bar
~bar
~foo
~refl
~disp
~disp_base
</code></pre>
<p>disp_base, base wird am Anfang 2x aufgerufen (!) und der Code stürzt mit einer Access Violation ab. Ich habe mit dem Debugger verifiziert, dass der Konstruktor-Aufruf den Stack zerschiesst und darum alles abstürzt.</p>
<p>Ist das ein Compilerfehler oder ist am Code per se etwas falsch?</p>
<p>$edit: Es scheint sich tatsächlich um eine Art Bug zu handeln? Habe gerade mit Visual C++ 2015 getestet und dort bekomme ich den Fehler nicht mehr und der Output ist derselbe wie beim GCC/LLVM.</p>
<p>FG</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/332840/virtual-inheritance-access-violation-fehler-oder-nicht</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 12:03:20 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/332840.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 May 2015 15:30:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Virtual Inheritance Access Violation - Fehler oder nicht? on Mon, 25 May 2015 15:41:45 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich kämpfe gerade mit einem Problem in Visual C++; mit LLVM und GCC tritt der Fehler nicht auf. Und zwar geht es um virtuelle Vererbung. Gegeben sei folgendes, eingedummtes Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

#define where_am_i std::cout &lt;&lt; __FUNCTION__ &lt;&lt; std::endl;

namespace test
{

    class disp_base
    {
    public:
        disp_base()
        {
            where_am_i
        }
        virtual ~disp_base()
        {
            where_am_i
        }
    };

    class disp : public virtual disp_base
    {
    public:
        disp()
        {
            where_am_i
        }
        virtual ~disp()
        {
            where_am_i
        }
    };

    class refl : public virtual disp_base
    {
    public:
        refl()
        {
            where_am_i
        }
        virtual ~refl()
        {
            where_am_i
        }
    };

    class foo : public virtual disp, public refl
    {
        void *something;
    public:
        foo() : foo(static_cast&lt;void *&gt;(this))
        {
            where_am_i
        }
        foo(void *test) : something(test)
        {
            where_am_i
        }
        virtual ~foo()
        {
            where_am_i
        }
    };

    class bar : public virtual foo
    {
    public:
        bar()
        {
            where_am_i
        }
        virtual ~bar()
        {
            where_am_i
        }
    };

}

int main()
{
    test::bar fail;
}
</code></pre>
<p>Mit GCC-4.9.2 erhalte ich folgenden Output:</p>
<pre><code>disp_base
disp
refl
foo
foo
bar
~bar
~foo
~refl
~disp
~disp_base
</code></pre>
<p>Auch LLVM frisst den Code problemlos. Mit Visual C++ 2013 hingegen erhalte ich folgendes:</p>
<pre><code>disp_base
disp
disp_base
disp
refl
foo
foo
bar
~bar
~foo
~refl
~disp
~disp_base
</code></pre>
<p>disp_base, base wird am Anfang 2x aufgerufen (!) und der Code stürzt mit einer Access Violation ab. Ich habe mit dem Debugger verifiziert, dass der Konstruktor-Aufruf den Stack zerschiesst und darum alles abstürzt.</p>
<p>Ist das ein Compilerfehler oder ist am Code per se etwas falsch?</p>
<p>$edit: Es scheint sich tatsächlich um eine Art Bug zu handeln? Habe gerade mit Visual C++ 2015 getestet und dort bekomme ich den Fehler nicht mehr und der Output ist derselbe wie beim GCC/LLVM.</p>
<p>FG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454709</guid><dc:creator><![CDATA[*rant*]]></dc:creator><pubDate>Mon, 25 May 2015 15:41:45 GMT</pubDate></item><item><title><![CDATA[Reply to Virtual Inheritance Access Violation - Fehler oder nicht? on Mon, 25 May 2015 17:32:14 GMT]]></title><description><![CDATA[<p>Ich würde von einem Fehler in VS2013 ausgehen.</p>
<p>Allerdings ist die Hierarchie schon etwas pervers <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2454739</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2454739</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 25 May 2015 17:32:14 GMT</pubDate></item></channel></rss>