<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Weird behaviour with enable_if and sizeof"
href="http://llvm.org/bugs/show_bug.cgi?id=15450">15450</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Weird behaviour with enable_if and sizeof
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.2
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>d.frey@gmx.de
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>When trying to implement a traits class, I stumbled upon a weird bug. Here's a
reduced testcase:
#include <type_traits>
template< typename, typename = void >
struct A : std::false_type {};
template< typename T >
struct A< T, typename std::enable_if< !!sizeof( std::declval< T >() ) >::type >
: std::true_type {};
// here ^^
struct B;
int main()
{
static_assert( A< int >::value, "int" );
static_assert( !A< B >::value, "B" );
}
The code as it is compiles fine, but when I remove the two exclamation marks
(marked "here ^^"), the behaviour changes:
$ clang++ -std=c++11 -pthread -O3 -Wall -Wextra t.cc -o t && ./t
t.cc:14:3: error: static_assert failed "int"
static_assert( A< int >::value, "int" );
^ ~~~~~~~~~~~~~~~
1 error generated.
$
Just to repeat: The error is without the two exclamation marks, the !! is the
work-around I'm using.
GCC 4.7 compiles both versions fine.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>