[LLVMbugs] [Bug 13397] New: enable_if referenced via a type alias triggers an error when condition is false

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 18 21:09:36 PDT 2012


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

             Bug #: 13397
           Summary: enable_if referenced via a type alias triggers an
                    error when condition is false
           Product: new-bugs
           Version: 3.1
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: paul at preney.ca
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 8920
  --> http://llvm.org/bugs/attachment.cgi?id=8920
Stripped down code that triggers bug.

When std::enable_if is used via a type alias and the condition works out to be
false, clang++ (v3.1) fails, e.g.,

template <bool Cond, typename T>
using guard = typename std::enable_if<Cond,T>::type;

i.e., when Cond is false, then the use of guard in code will cause a
compile-time error. It appears if type does not resolve to a type (as it might
with enable if) clang++ cannot handle it.

With the attached, clang++ reporting these compile-time errors with the code:

$ clang++ -std=c++11 enableif.cxx 
enableif.cxx:5:1: error: no type named 'type' in 'std::enable_if<false, int>'
using guard = typename std::enable_if<Cond,T>::type;
^~~~~
enableif.cxx:16:3: note: in instantiation of template type alias 'guard'
requested here
  guard<!Cond, int>
  ^
enableif.cxx:15:6: note: while substituting explicitly-specified template
arguments into
      function template 'test'
auto test() ->
     ^
enableif.cxx:5:1: error: no type named 'type' in 'std::enable_if<false, int>'
using guard = typename std::enable_if<Cond,T>::type;
^~~~~
2 errors generated.
$

The version of clang++ is:

$ clang++ -v
clang version 3.1 (branches/release_31)
Target: x86_64-pc-linux-gnu
Thread model: posix
$


NOTE: With GCC's g++ (e.g., v4.7, v4.8 snapshot 20120715) it compiles and
outputs "5,10" (which is the desired and correct behaviour).

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list