<?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[RVO und&#x2F;oder Bug?]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich bin gerade auf etwas Komisches gestoßen (VS2013 Update 1):<br />
(Sinn: Will die Klasse in einer DLL haben und Create exportieren, ScopeLock macht aber nur am Stack Sinn, daher dachte ich mir, ein Stack-Objekt &quot;rauszumoven&quot; :D)</p>
<pre><code>class ScopeLock
{
	CRITICAL_SECTION&amp; criticalSection;
	bool locked;
public:
	ScopeLock(CRITICAL_SECTION&amp; criticalSection);
	~ScopeLock();
	ScopeLock(ScopeLock&amp;&amp;) = delete;
	ScopeLock() = delete;
	ScopeLock(const ScopeLock&amp;) = delete;
	ScopeLock&amp; operator=(const ScopeLock&amp;) = delete;
	static ScopeLock Create(CRITICAL_SECTION&amp; criticalSection);
	void Lock();
	void Unlock();
};

ScopeLock::ScopeLock(CRITICAL_SECTION&amp; criticalSection) : criticalSection(criticalSection), locked(true)
{
	cout &lt;&lt; &quot;new lock: &quot; &lt;&lt;  this &lt;&lt; endl;

	EnterCriticalSection(&amp;criticalSection);
}

ScopeLock::~ScopeLock()
{
	if(locked)
	{
		cout &lt;&lt; &quot;unlock: &quot; &lt;&lt; this &lt;&lt; endl;

		LeaveCriticalSection(&amp;criticalSection);
	}
}

ScopeLock ScopeLock::Create(CRITICAL_SECTION&amp; criticalSection)
{
	return ScopeLock(criticalSection);
}

void ScopeLock::Lock()
{
	locked = true;
	EnterCriticalSection(&amp;criticalSection);
}

void ScopeLock::Unlock()
{
	LeaveCriticalSection(&amp;criticalSection);
	locked = false;
}

int main()
{
	CRITICAL_SECTION cs;
	InitializeCriticalSection(&amp;cs);

	{
		auto lock = ScopeLock::Create(cs);
	}
}
</code></pre>
<p>Ausgabe:<br />
new lock: 003BF7DC<br />
unlock: 003BF7DC</p>
<p>Visual Studio zeigt in Zeile 35 und 56 einen Fehler (rot unterstrichen, egal wie oft ich rescanne oder neu öffne), kompiliert aber trotzdem fehlerfrei <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Die Fehler bei mouseover lauten in etwa &quot;error: move constr. can't be referenced - is deleted&quot;.</p>
<p>Was ist da los? Da wird scheinbar RVO angewandt? Und warum will der da eigentlich den move constructor aufrufen und nicht den copy constructor?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/324919/rvo-und-oder-bug</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 09:10:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/324919.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 07 Apr 2014 22:37:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to RVO und&#x2F;oder Bug? on Mon, 07 Apr 2014 22:37:54 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich bin gerade auf etwas Komisches gestoßen (VS2013 Update 1):<br />
(Sinn: Will die Klasse in einer DLL haben und Create exportieren, ScopeLock macht aber nur am Stack Sinn, daher dachte ich mir, ein Stack-Objekt &quot;rauszumoven&quot; :D)</p>
<pre><code>class ScopeLock
{
	CRITICAL_SECTION&amp; criticalSection;
	bool locked;
public:
	ScopeLock(CRITICAL_SECTION&amp; criticalSection);
	~ScopeLock();
	ScopeLock(ScopeLock&amp;&amp;) = delete;
	ScopeLock() = delete;
	ScopeLock(const ScopeLock&amp;) = delete;
	ScopeLock&amp; operator=(const ScopeLock&amp;) = delete;
	static ScopeLock Create(CRITICAL_SECTION&amp; criticalSection);
	void Lock();
	void Unlock();
};

ScopeLock::ScopeLock(CRITICAL_SECTION&amp; criticalSection) : criticalSection(criticalSection), locked(true)
{
	cout &lt;&lt; &quot;new lock: &quot; &lt;&lt;  this &lt;&lt; endl;

	EnterCriticalSection(&amp;criticalSection);
}

ScopeLock::~ScopeLock()
{
	if(locked)
	{
		cout &lt;&lt; &quot;unlock: &quot; &lt;&lt; this &lt;&lt; endl;

		LeaveCriticalSection(&amp;criticalSection);
	}
}

ScopeLock ScopeLock::Create(CRITICAL_SECTION&amp; criticalSection)
{
	return ScopeLock(criticalSection);
}

void ScopeLock::Lock()
{
	locked = true;
	EnterCriticalSection(&amp;criticalSection);
}

void ScopeLock::Unlock()
{
	LeaveCriticalSection(&amp;criticalSection);
	locked = false;
}

int main()
{
	CRITICAL_SECTION cs;
	InitializeCriticalSection(&amp;cs);

	{
		auto lock = ScopeLock::Create(cs);
	}
}
</code></pre>
<p>Ausgabe:<br />
new lock: 003BF7DC<br />
unlock: 003BF7DC</p>
<p>Visual Studio zeigt in Zeile 35 und 56 einen Fehler (rot unterstrichen, egal wie oft ich rescanne oder neu öffne), kompiliert aber trotzdem fehlerfrei <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Die Fehler bei mouseover lauten in etwa &quot;error: move constr. can't be referenced - is deleted&quot;.</p>
<p>Was ist da los? Da wird scheinbar RVO angewandt? Und warum will der da eigentlich den move constructor aufrufen und nicht den copy constructor?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393271</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393271</guid><dc:creator><![CDATA[mhat]]></dc:creator><pubDate>Mon, 07 Apr 2014 22:37:54 GMT</pubDate></item><item><title><![CDATA[Reply to RVO und&#x2F;oder Bug? on Mon, 07 Apr 2014 23:22:23 GMT]]></title><description><![CDATA[<p>Wieso meinst du dass der Copy-Ctor aufgerufen werden sollte?<br />
Also vorausgesetzt es gäbe sowohl einen Copy-Ctor als auch einen Move-Ctor... dann würde ich schon erwarten dass er den Move-Ctor nimmt. Das Ding dass du zurückgibst ist ja wohl ganz klar ne Rvalue...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393276</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393276</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Mon, 07 Apr 2014 23:22:23 GMT</pubDate></item><item><title><![CDATA[Reply to RVO und&#x2F;oder Bug? on Tue, 08 Apr 2014 05:35:57 GMT]]></title><description><![CDATA[<p>Ähh klar... sry, war schon zu spät :p</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393286</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393286</guid><dc:creator><![CDATA[mhat]]></dc:creator><pubDate>Tue, 08 Apr 2014 05:35:57 GMT</pubDate></item><item><title><![CDATA[Reply to RVO und&#x2F;oder Bug? on Tue, 08 Apr 2014 06:34:44 GMT]]></title><description><![CDATA[<p>Rote Kringel sind völlig uninteressant! Wenn der Compiler keine Fehler oder Warnungen ausspuckt ist alles ok.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393290</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393290</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Tue, 08 Apr 2014 06:34:44 GMT</pubDate></item><item><title><![CDATA[Reply to RVO und&#x2F;oder Bug? on Tue, 08 Apr 2014 07:16:34 GMT]]></title><description><![CDATA[<p>Und was passiert da jetzt genau?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393294</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393294</guid><dc:creator><![CDATA[mhat]]></dc:creator><pubDate>Tue, 08 Apr 2014 07:16:34 GMT</pubDate></item><item><title><![CDATA[Reply to RVO und&#x2F;oder Bug? on Tue, 08 Apr 2014 07:18:22 GMT]]></title><description><![CDATA[<p>Wenn ich den move constructor definiere, verschwinden die scheinbaren Fehler, jedoch wird er nie aufgerufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393296</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393296</guid><dc:creator><![CDATA[mhat]]></dc:creator><pubDate>Tue, 08 Apr 2014 07:18:22 GMT</pubDate></item><item><title><![CDATA[Reply to RVO und&#x2F;oder Bug? on Tue, 08 Apr 2014 08:33:07 GMT]]></title><description><![CDATA[<p>Das sollte nicht kompilieren. Es ist egal, ob die Temporarys elidiert werden oder nicht, ein applikabler Move/Copy-Ctor muss vorhanden sein. Das ist offensichtlich nicht der Fall.</p>
<blockquote>
<p>When the criteria for elision of a copy operation are met [...], overload resolution to select the constructor for the copy is first performed as if the object were designated by an rvalue.<br />
If overload resolution fails, or if the type of the first parameter of the selected constructor is not an rvalue reference to the object’s type (possibly cv-qualified), overload resolution is performed again, considering the object as an<br />
lvalue.<br />
[ Note: <strong>This two-stage overload resolution must be performed regardless of whether copy elision will occur. It determines the constructor to be called if elision is not performed, and the selected constructor must be accessible even if the call is elided.</strong> — end note ]</p>
</blockquote>
<p>Edit: Man kann jetzt diskutieren, was genau der Standard von der ausgewählten Funktion erwartet. Hier darf sie jedoch nicht deleted sein, weil Overload Resolution den Move-Konstruktor auswählt, und</p>
<blockquote>
<p>A program that refers to a deleted function implicitly or explicitly, other than to declare it, is ill-formed.<br />
[ Note: [...] If a function is overloaded, it is referenced only if the function is selected by overload resolution. — end note ]</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2393316</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393316</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 08 Apr 2014 08:33:07 GMT</pubDate></item></channel></rss>