Note that there are some explanatory texts on larger screens.

plurals
  1. POVariadic template code compiles on GCC 4.6 but not on clang or GCC 4.7
    primarykey
    data
    text
    <p>I have this code (simplified from a more complex version):</p> <pre><code>template &lt;class... A1&gt; class Test { public: template &lt;class... A2&gt; void print (void(*function)(A2...,A1...)) { } }; void test_print (int a, float b, double c) { } int main () { Test&lt;float,double&gt; test; test.print&lt;int&gt; (&amp;test_print); } </code></pre> <p>If I compile it on GCC 4.6.3 using <code>g++ -std=c++0x filename.cpp</code> it compiles fine however on clang 3.0 using <code>clang++ -std=c++0x filename.cpp</code> it throws the following error:</p> <pre><code>filename.cpp:14:10: error: no matching member function for call to 'print' test.print&lt;int&gt; (&amp;test_print); ~~~~~^~~~~~~~~~ filename.cpp:3:33: note: candidate template ignored: failed template argument deduction template &lt;class... A2&gt; void print (void(*function)(A2...,A1...)) { ^ 1 error generated. </code></pre> <p>On GCC 4.7.2 there is also an error:</p> <pre><code>filename.cpp: In function 'int main()': filename.cpp:14:33: error: no matching function for call to 'Test&lt;float, double&gt;::print(void (*)(int, float, double))' filename.cpp:14:33: note: candidate is: filename.cpp:3:33: note: template&lt;class ... A2&gt; void Test::print(void (*)(A2 ..., A1 ...)) [with A2 = {A2 ...}; A1 = {float, double}] filename.cpp:3:33: note: template argument deduction/substitution failed: filename.cpp:14:33: note: mismatched types 'float' and 'int' </code></pre> <p>Now the question is: why is it failing or what am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload