<?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[Fehler in folly&#x2F;ScopeGuard.h?]]></title><description><![CDATA[<p>Da: <a href="https://github.com/facebook/folly/blob/master/folly/ScopeGuard.h" rel="nofollow">https://github.com/facebook/folly/blob/master/folly/ScopeGuard.h</a></p>
<p>Wenn man schreibt (wie im Kommentar beschrieben)</p>
<pre><code class="language-cpp">ScopeGuard guard = makeGuard([&amp;] { friends_.pop_back(); });
</code></pre>
<p>ist das dann nicht UB wenn der Destruktor aufgerufen wird?</p>
<p>Meine Interpretation: <code>ScopeGuard</code> ist nur ein Typedef auf <code>ScopeGuardImplBase&amp;&amp;</code> und <code>makeGuard</code> gibt eine davon abgeleitete Klasse zurück. Der Destruktor ist nicht virtuell.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/314337/fehler-in-folly-scopeguard-h</link><generator>RSS for Node</generator><lastBuildDate>Sat, 01 Aug 2026 09:48:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/314337.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Feb 2013 16:17:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Wed, 27 Feb 2013 16:17:46 GMT]]></title><description><![CDATA[<p>Da: <a href="https://github.com/facebook/folly/blob/master/folly/ScopeGuard.h" rel="nofollow">https://github.com/facebook/folly/blob/master/folly/ScopeGuard.h</a></p>
<p>Wenn man schreibt (wie im Kommentar beschrieben)</p>
<pre><code class="language-cpp">ScopeGuard guard = makeGuard([&amp;] { friends_.pop_back(); });
</code></pre>
<p>ist das dann nicht UB wenn der Destruktor aufgerufen wird?</p>
<p>Meine Interpretation: <code>ScopeGuard</code> ist nur ein Typedef auf <code>ScopeGuardImplBase&amp;&amp;</code> und <code>makeGuard</code> gibt eine davon abgeleitete Klasse zurück. Der Destruktor ist nicht virtuell.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302623</guid><dc:creator><![CDATA[schkopa]]></dc:creator><pubDate>Wed, 27 Feb 2013 16:17:46 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Wed, 27 Feb 2013 16:24:07 GMT]]></title><description><![CDATA[<p>Ich muss nochmal drueber schauen ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302625</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302625</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 27 Feb 2013 16:24:07 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Wed, 27 Feb 2013 17:20:35 GMT]]></title><description><![CDATA[<p>schkopa schrieb:</p>
<blockquote>
<p>Meine Interpretation: <code>ScopeGuard</code> ist nur ein Typedef auf <code>ScopeGuardImplBase&amp;&amp;</code> und <code>makeGuard</code> gibt eine davon abgeleitete Klasse zurück. Der Destruktor ist nicht virtuell.</p>
</blockquote>
<p>Muss er auch nicht sein. Das Objekt wird ja nicht über die Referenz gelöscht. Es lebt im automatischen Speicher und verschwindet von ganz allein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302629</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302629</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Wed, 27 Feb 2013 17:20:35 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Wed, 27 Feb 2013 16:44:35 GMT]]></title><description><![CDATA[<p>Ja die Frage ist, wie sich das Objekt an die rvalue reference binden laesst und warum es bis zum Ende des Scopes lebt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302634</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302634</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Wed, 27 Feb 2013 16:44:35 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Wed, 27 Feb 2013 16:50:29 GMT]]></title><description><![CDATA[<p>knivil schrieb:</p>
<blockquote>
<p>Ja die Frage ist, wie sich das Objekt an die rvalue reference binden laesst und warum es bis zum Ende des Scopes lebt.</p>
</blockquote>
<p>Kann sehr gut sein, dass ich da die entsprechenden Regeln nicht kenne. Kannst du ein Stichwort nennen, krümelkacker?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302635</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302635</guid><dc:creator><![CDATA[schkopa]]></dc:creator><pubDate>Wed, 27 Feb 2013 16:50:29 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Wed, 27 Feb 2013 17:16:38 GMT]]></title><description><![CDATA[<p>C++11, 12.2 p 4-5</p>
<blockquote>
<p>There are two contexts in which temporaries are destroyed at a different point than the end of the full expression. The first [...]<br />
The second context is when a reference is bound to a temporary. The temporary to which the reference is bound or the temporary that is the complete object of a subobject to which the reference is bound persists for the lifetime of the reference except:</p>
<ul>
<li>A temporary bound to a reference member in a constructor’s ctor-initializer (12.6.2) persists until the constructor exits.</li>
<li>A temporary bound to a reference parameter in a function call (5.2.2) persists until the completion of the full-expression containing the call.</li>
<li>The lifetime of a temporary bound to the returned value in a function return statement (6.6.3) is not extended; the temporary is destroyed at the end of the full-expression in the return statement.</li>
<li>A temporary bound to a reference in a new-initializer (5.3.4) persists until the completion of the full-expression containing the new-initializer. [...] [ Note: This may introduce a dangling reference, and implementations are encouraged to issue a warning in such a case. —end note ]</li>
</ul>
</blockquote>
<p>Siehe auch Herb Sutter's Artikel:<br />
<a href="http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/" rel="nofollow">A Candidate for the Most Important Const</a></p>
<p>In C++11 gilt das eben auch für Rvalue-Referenzen. Das wird sogar in der Definition des for-range Loops ausgenutzt:</p>
<pre><code class="language-cpp">auto&amp;&amp; __range = range_expression;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2302641</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302641</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Wed, 27 Feb 2013 17:16:38 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Thu, 28 Feb 2013 09:43:56 GMT]]></title><description><![CDATA[<p>Nicht schlecht Herr specht. Bin von ScopeGuard begeistert. Schoen wie RAII, Vererbung und Rvalue-Referenzen (neben Templates und std::function) hier zusammenarbeitet. Dabei ist Vererbung genutzt worden, um sowas wie type erasure zu realisieren.</p>
<p>Mir war schon klar, dass T&amp; nicht an temporaere Objekte gebunden werden kann. Auf der anderen Seite wird ja immer gesagt, dass T&amp;&amp; auch erstmal normale Referenzen sind, hier aber ein deutlicher Unterschied besteht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302773</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302773</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 28 Feb 2013 09:43:56 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Thu, 28 Feb 2013 10:09:01 GMT]]></title><description><![CDATA[<p>Also Referenzen und R-Value-Referenzen entscheinden sich in dem Punkt</p>
<blockquote>
<p>The lifetime of a temporary bound to the returned value in a function return statement (6.6.3) is not extended; the temporary is destroyed at the end of the full-expression in the return statement.</p>
</blockquote>
<p>voneinander?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302789</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 28 Feb 2013 10:09:01 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Thu, 28 Feb 2013 11:04:05 GMT]]></title><description><![CDATA[<p>&quot;temporaer&quot; war wahrscheinlich der falsche Begriff. Auch kann ich mit dem zitierten Fetzen wenig anfangen, da der Bezug fehlt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302808</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Thu, 28 Feb 2013 11:04:05 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Thu, 28 Feb 2013 11:12:13 GMT]]></title><description><![CDATA[<p>Decimad schrieb:</p>
<blockquote>
<p>Also Referenzen und R-Value-Referenzen entscheinden sich in dem Punkt</p>
<blockquote>
<p>The lifetime of a temporary bound to the returned value in a function return statement (6.6.3) is not extended; the temporary is destroyed at the end of the full-expression in the return statement.</p>
</blockquote>
<p>voneinander?</p>
</blockquote>
<p>Nein, wieso?</p>
<pre><code class="language-cpp">struct foo{};
const foo&amp; f() { return foo(); }
foo&amp;&amp; g() { return foo(); }

f();  // Referenz ist ungültig
g();  // Referenz ist ungültig
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2302817</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302817</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Thu, 28 Feb 2013 11:12:13 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Thu, 28 Feb 2013 11:57:05 GMT]]></title><description><![CDATA[<p>Oder anders:</p>
<pre><code class="language-cpp">struct foo {};
foo make_foo() { return foo(); }

foo&amp; a  = make_foo();
foo&amp;&amp; b = make_foo();

// a ungültige referenz, b gültige referenz?
</code></pre>
<p>Ich komme hier gerade etwas ins Straucheln, weil ich halt mit dem genauen Wortlaut der Regeln mangels Vokabulardefinitionen nicht so viel anfangen kann.<br />
Mich wundert halt, warum der Code von ScopeGuardImpl eine R-Value-Referenz als Lebensverländerer benutzt (benutzen muss?), statt einer normalen Referenz.</p>
<p>Edit:<br />
Hier stand Grütze. (&quot;foo c = make_foo()&quot;). Referenz wird ja genommen, damit man kein Type-Slicing betreibt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302832</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302832</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 28 Feb 2013 11:57:05 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Thu, 28 Feb 2013 12:17:31 GMT]]></title><description><![CDATA[<p>Alternativ gingen ja auch auto oder auto&amp;&amp;.</p>
<p>Eine Lvalue-Referenz auf Nicht-Const wird nicht funktionieren, weil man solche Referenzen nicht so initialisiert bekommt, dass sie auf ein temporäres Objekt verweisen.</p>
<p>Eine Lvalue-Referenz auf Const ist da nicht angebracht, weil man das ScopeGuard-Objekt noch verändern können will (siehe dismiss-Funktion).</p>
<p>Das einzig Sinnige hier ist wirklich eine Rvalue-Referenz oder eben auto.</p>
<p>Decimad schrieb:</p>
<blockquote>
<pre><code class="language-cpp">struct foo {};
foo make_foo() { return foo(); }

foo&amp; a  = make_foo();
foo&amp;&amp; b = make_foo();

// a ungültige referenz, b gültige referenz?
</code></pre>
</blockquote>
<p>Bei a würde noch ein const fehlen, da du sonst die Lvalue-Referenz nicht initialisiert bekommst.</p>
<pre><code class="language-cpp">struct foo {};
foo make_foo(int v) { return foo(); }

int main()
{
  foo const&amp; a = make_foo();
  foo     &amp;&amp; b = make_foo();
  return 0;
}
</code></pre>
<p>Hier bleiben die Referenzen a und b beide gültig, weil die Lebenszeit der temporären foo-Objekte verlängert wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302846</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302846</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Thu, 28 Feb 2013 12:17:31 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler in folly&#x2F;ScopeGuard.h? on Thu, 28 Feb 2013 12:12:05 GMT]]></title><description><![CDATA[<p>krümelkacker schrieb:</p>
<blockquote>
<p>[...]<br />
Eine Lvalue-Referenz auf Nicht-Const wird nicht funktionieren, weil man solche Referenzen nicht so initialisiert bekommt, dass sie auf ein temporäres Objekt verweisen.<br />
[...]</p>
</blockquote>
<p>Das ist mir jetzt mal wieder unangenehm, die Regel hätte ich ja nun kennen müssen -.- Schaue ich mir heute Abend mal an, warum dem so sein muss, verschwendet keine Mühe auf mich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Danke für die Klarstellung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2302847</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2302847</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Thu, 28 Feb 2013 12:12:05 GMT</pubDate></item></channel></rss>