On Thu, Sep 13, 2012 at 9:21 AM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br><br><div class="gmail_quote"><div class="im">On Thu, Sep 13, 2012 at 7:31 AM, Ansgar Burchardt <span dir="ltr"><<a href="mailto:ansgar.burchardt@iwr.uni-heidelberg.de" target="_blank">ansgar.burchardt@iwr.uni-heidelberg.de</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm not sure if this is the right list, but I encountered a problem with<br>
std::enable_if in clang++:<br>
<br>
---<br>
#include <iostream><br>
#include <type_traits><br>
<br>
template<int n><br>
struct A {<br>
  enum { a = n };<br>
};<br>
<br>
template<class T, typename dummy = void><br>
struct B<br>
{<br>
  enum { b = 1 };<br>
};<br>
<br>
template<class T><br>
struct B<T, typename std::enable_if<T::a>::type><br>
{<br>
  enum { b = 2 };<br>
};<br>
<br>
int main(void)<br>
{<br>
  std::cout << B< A<1> >::b << std::endl;<br>
  std::cout << B< A<2> >::b << std::endl;<br>
}<br>
---<br>
<br>
This will give "2 1" with clang 3.1-8 (Debian), but "2 2" with g++<br>
4.7.1-8 (Debian).  I'm far from being an expert in C++, but shouldn't<br>
both lines use the specialized version of B (ie. g++ is correct)?<br></blockquote><div><br></div></div><div>No, this program's behavior changed in C++11. Converting a constant 2 to bool is a narrowing conversion, which is disallowed in a converted constant expression such as a non-type template argument. G++ apparently doesn't implement that rule yet.</div>

<div><br></div><div>The second result should also be '1' in C++11 mode -- this is another C++11-specific change. I brought this to the committee's attention in DR1407, and we agreed that this was the desired behavior, but no compiler has implemented it yet (as far as I'm aware).</div>
</div></blockquote><div><br></div><div>I implemented DR1407 in r163829. We now produce "1 1" in C++11 mode and "2 2" in C++98 mode.</div></div>