[LLVMbugs] [Bug 15450] New: Weird behaviour with enable_if and sizeof

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Mar 5 10:19:31 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=15450

            Bug ID: 15450
           Summary: Weird behaviour with enable_if and sizeof
           Product: clang
           Version: 3.2
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: d.frey at gmx.de
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130305/4e6aaeb9/attachment.html>


More information about the llvm-bugs mailing list