<?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[Seltsamer Fehler beim template meta programming.]]></title><description><![CDATA[<p>Hallo Forum!</p>
<p>Ich habe den folgenden Quellcode:</p>
<pre><code>template&lt;int x, int y&gt;
class add
{
public:
  const static int is = x + y;
};

template &lt;int x&gt;
class add1
{
public:
  const int is = add&lt;1, x&gt;::is;
};
</code></pre>
<p>Wenn ich den mit <code>g++ -std=c++11</code> compiliere bekomme ich die folgenden Fehler, die ich nicht verstehe:</p>
<pre><code>test.cpp:12:25: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
   const int is = add&lt;1, x&gt;::is;
                         ^
test.cpp:12:25: error: expected ‘;’ at end of member declaration
test.cpp:12:25: error: declaration of ‘const int add1&lt;x&gt;::x’
test.cpp:8:11: error:  shadows template parm ‘int x’
 template &lt;int x&gt;
           ^
test.cpp:12:26: error: expected unqualified-id before ‘&gt;’ token
   const int is = add&lt;1, x&gt;::is;
                          ^
test.cpp:12:22: error: wrong number of template arguments (1, should be 2)
   const int is = add&lt;1, x&gt;::is;
                      ^
test.cpp:2:7: error: provided for ‘template&lt;int x, int y&gt; class add’
 class add
       ^
</code></pre>
<p>Wenn ich in Zeile 12 die RHS in Klammern setze, treten die Fehler nicht auf:</p>
<pre><code>const int is = (add&lt;1, x&gt;::is);
</code></pre>
<p>Wenn ich in Zeile 12 das x und die 1 austausche, treten die Fehler ebenfalls nicht auf:</p>
<pre><code>const int is = add&lt;x, 1&gt;::is;
</code></pre>
<p>Wenn ich in Zeile 12 ein static hinzufüge, treten die Fehler ebenfalls nicht auf:</p>
<pre><code>const static int is = add&lt;1, x&gt;::is;
</code></pre>
<p>Wenn ich den Code mit clang kompilieren treten die Fehler ebenfalls nicht auf.</p>
<p>Was ist da los? Ist das vielleicht ein Bug in G++?</p>
<p>Vielen Dank im Voraus!</p>
<p>Mit freundlichen Grüßen<br />
Ǹíłŝ</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/331791/seltsamer-fehler-beim-template-meta-programming</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 04:00:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/331791.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 20 Mar 2015 14:22:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 14:22:17 GMT]]></title><description><![CDATA[<p>Hallo Forum!</p>
<p>Ich habe den folgenden Quellcode:</p>
<pre><code>template&lt;int x, int y&gt;
class add
{
public:
  const static int is = x + y;
};

template &lt;int x&gt;
class add1
{
public:
  const int is = add&lt;1, x&gt;::is;
};
</code></pre>
<p>Wenn ich den mit <code>g++ -std=c++11</code> compiliere bekomme ich die folgenden Fehler, die ich nicht verstehe:</p>
<pre><code>test.cpp:12:25: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
   const int is = add&lt;1, x&gt;::is;
                         ^
test.cpp:12:25: error: expected ‘;’ at end of member declaration
test.cpp:12:25: error: declaration of ‘const int add1&lt;x&gt;::x’
test.cpp:8:11: error:  shadows template parm ‘int x’
 template &lt;int x&gt;
           ^
test.cpp:12:26: error: expected unqualified-id before ‘&gt;’ token
   const int is = add&lt;1, x&gt;::is;
                          ^
test.cpp:12:22: error: wrong number of template arguments (1, should be 2)
   const int is = add&lt;1, x&gt;::is;
                      ^
test.cpp:2:7: error: provided for ‘template&lt;int x, int y&gt; class add’
 class add
       ^
</code></pre>
<p>Wenn ich in Zeile 12 die RHS in Klammern setze, treten die Fehler nicht auf:</p>
<pre><code>const int is = (add&lt;1, x&gt;::is);
</code></pre>
<p>Wenn ich in Zeile 12 das x und die 1 austausche, treten die Fehler ebenfalls nicht auf:</p>
<pre><code>const int is = add&lt;x, 1&gt;::is;
</code></pre>
<p>Wenn ich in Zeile 12 ein static hinzufüge, treten die Fehler ebenfalls nicht auf:</p>
<pre><code>const static int is = add&lt;1, x&gt;::is;
</code></pre>
<p>Wenn ich den Code mit clang kompilieren treten die Fehler ebenfalls nicht auf.</p>
<p>Was ist da los? Ist das vielleicht ein Bug in G++?</p>
<p>Vielen Dank im Voraus!</p>
<p>Mit freundlichen Grüßen<br />
Ǹíłŝ</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447433</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447433</guid><dc:creator><![CDATA[&amp;amp;#504;í&amp;amp;#322;&amp;amp]]></dc:creator><pubDate>Fri, 20 Mar 2015 14:22:17 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 15:28:14 GMT]]></title><description><![CDATA[<p>Bei Add1 fehlt das static vor is. Das willst du auch aus semantischen Gründen.<br />
Die anderen &quot;Lösungen&quot; sehen nach Compilerbugs aus, ja.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447447</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Fri, 20 Mar 2015 15:28:14 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 16:20:31 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Bei Add1 fehlt das static vor is. Das willst du auch aus semantischen Gründen.</p>
</blockquote>
<p>Okay, warum brauche ich das static? Ich dachte in C++11 ist das dort nicht mehr nötig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447455</guid><dc:creator><![CDATA[&amp;amp;#504;í&amp;amp;#322;&amp;amp]]></dc:creator><pubDate>Fri, 20 Mar 2015 16:20:31 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 16:36:52 GMT]]></title><description><![CDATA[<p>Hm?</p>
<p>Das static macht natuerlich auch in c++11 einen Unterschied:</p>
<pre><code>class foo
{
    int i;
    static int si; // ist nicht dasselbe wie i
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2447457</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447457</guid><dc:creator><![CDATA[Hyde++ 0]]></dc:creator><pubDate>Fri, 20 Mar 2015 16:36:52 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 16:57:41 GMT]]></title><description><![CDATA[<blockquote>
<p>Ich habe den folgenden Quellcode:</p>
</blockquote>
<p>Joa, der ist korrekt (i.e. standardkonform). Version von GCC?</p>
<blockquote>
<p>Ich dachte in C++11 ist das dort nicht mehr nötig?</p>
</blockquote>
<p>Korrekt. Nathan hat da wohl was verwechselt. (Oder ich misinterpretiere seinen Post.)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447459</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 20 Mar 2015 16:57:41 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 17:01:06 GMT]]></title><description><![CDATA[<p>Ǹíł&amp; schrieb:</p>
<blockquote>
<p>Wenn ich den mit <code>g++ -std=c++11</code> compiliere bekomme ich die folgenden Fehler, die ich nicht verstehe:</p>
<pre><code>test.cpp:12:25: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
</code></pre>
</blockquote>
<p>Bist du sicher, dass du -std=c++11 übergeben hast?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447460</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447460</guid><dc:creator><![CDATA[backquestion]]></dc:creator><pubDate>Fri, 20 Mar 2015 17:01:06 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 17:31:05 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Ich dachte in C++11 ist das dort nicht mehr nötig?</p>
</blockquote>
<p>Korrekt. Nathan hat da wohl was verwechselt. (Oder ich misinterpretiere seinen Post.)</p>
</blockquote>
<p>Ich ging davon aus, dass er wegen TMP eine static Membervariable wollte. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447466</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447466</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Fri, 20 Mar 2015 17:31:05 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 17:46:27 GMT]]></title><description><![CDATA[<p>Nathan schrieb:</p>
<blockquote>
<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Ich dachte in C++11 ist das dort nicht mehr nötig?</p>
</blockquote>
<p>Korrekt. Nathan hat da wohl was verwechselt. (Oder ich misinterpretiere seinen Post.)</p>
</blockquote>
<p>Ich ging davon aus, dass er wegen TMP eine static Membervariable wollte. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f4a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--light_bulb"
      title=":bulb:"
      alt="💡"
    /></p>
</blockquote>
<p>Ja, das hast du bereits dadurch deutlich gemacht dass du</p>
<blockquote>
<p>Das willst du <strong>auch</strong> aus semantischen Gründen.</p>
</blockquote>
<p>geschrieben hast. Beachte aber den Fett markierten Teil: Was war der primäre, andere Grund? Oder verstehe ich &quot;semantischer Grund&quot; falsch? Das bezieht sich doch darauf dass man bei TMP fast ausschließlich <em>statische</em> Member hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447467</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 20 Mar 2015 17:46:27 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 18:19:15 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Das willst du <strong>auch</strong> aus semantischen Gründen.</p>
</blockquote>
<p>geschrieben hast. Beachte aber den Fett markierten Teil: Was war der primäre, andere Grund? Oder verstehe ich &quot;semantischer Grund&quot; falsch? Das bezieht sich doch darauf dass man bei TMP fast ausschließlich <em>statische</em> Member hat.</p>
</blockquote>
<p>Das &quot;semantische Gründe&quot; bezog sich auf die Tatsache, dass man mit statischen Member arbeitet, ja.<br />
Der andere Grund wäre: damit es kompiliert.<br />
Ich habe den Post vom TO nicht genau gelesen und ging von der Fehlermeldung davon aus, dass er <em>kein</em> C++11 verwendet. Demzufolge ist der primäre Grund, dass Ding zum Compilieren zu bringen und deshalb habe ich auch den Rest als Bug interpretiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447476</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447476</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Fri, 20 Mar 2015 18:19:15 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 20:49:47 GMT]]></title><description><![CDATA[<p>backquestion schrieb:</p>
<blockquote>
<p>Ǹíłŝ schrieb:</p>
<blockquote>
<p>Wenn ich den mit <code>g++ -std=c++11</code> compiliere bekomme ich die folgenden Fehler, die ich nicht verstehe:</p>
<pre><code>test.cpp:12:25: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
</code></pre>
</blockquote>
<p>Bist du sicher, dass du -std=c++11 übergeben hast?</p>
</blockquote>
<p>Du hast recht, das hatte ich vergessen. Mit dem Parameter bleiben der Rest der Fehlermeldungen allerdings die selben.</p>
<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>Ich habe den folgenden Quellcode:</p>
</blockquote>
<p>Joa, der ist korrekt (i.e. standardkonform). Version von GCC?</p>
</blockquote>
<p>Ich habe die aktuelle GCC Version aus dem testing Zweir von Arch Linux:<br />
gcc version 4.9.2 20150304 (prerelease) (GCC)</p>
<p>Hm, vielleicht sollte ich kein Prerelease verwenden. <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 />
Mal schauen, ob es einen Eintrag in Bugzilla gibt...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447498</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447498</guid><dc:creator><![CDATA[&amp;amp;#504;í&amp;amp;#322;&amp;amp]]></dc:creator><pubDate>Fri, 20 Mar 2015 20:49:47 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Fri, 20 Mar 2015 21:54:40 GMT]]></title><description><![CDATA[<blockquote>
<p>Hm, vielleicht sollte ich kein Prerelease verwenden.</p>
</blockquote>
<p>Quatsch, der Bug ist im normalen Release ebenfalls vorhanden. Siehe Coliru - also ja, hast nen Bug gefunden, Glückwunsch. Reporten und die Sache ist abgehakt. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2447505</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447505</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 20 Mar 2015 21:54:40 GMT</pubDate></item><item><title><![CDATA[Reply to Seltsamer Fehler beim template meta programming. on Sun, 22 Mar 2015 15:37:41 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>also ja, hast nen Bug gefunden, Glückwunsch. Reporten und die Sache ist abgehakt. <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>
</blockquote>
<p>Der Bug ist offenbar schon seit drei Jahren bekannt und wird nicht gefixt:<br />
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52595" rel="nofollow">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52595</a><br />
Seltsam. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447628</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447628</guid><dc:creator><![CDATA[&amp;amp;#504;í&amp;amp;#322;&amp;amp]]></dc:creator><pubDate>Sun, 22 Mar 2015 15:37:41 GMT</pubDate></item></channel></rss>