[LLVMbugs] [Bug 15673] New: poor diagnostic for deduction failure in default template argument

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Apr 4 10:51:15 PDT 2013


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

            Bug ID: 15673
           Summary: poor diagnostic for deduction failure in default
                    template argument
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zilla at kayari.org
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The change made by
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120507/057436.html
is excellent, but only seems to work for old fashioned uses of enable_if, in
return types or function parameters.

My preferred style is to de-clutter the function declaration by using enable_if
in a template parameter with a default template argument e.g.

#include <type_traits>

template<typename T>
struct a_trait : std::false_type { };

template<typename T,
         typename Requires = typename std::enable_if<a_trait<T>::value>::type>
void foo() { }

int main()
{
    foo<int>();
}

Clang is not very helpful here:

b.cc:12:5: error: no matching function for call to 'foo'
    foo<int>();
    ^~~~~~~~
b.cc:8:6: note: candidate template ignored: couldn't infer template argument
'Requires'
void foo() { }
     ^


In an ideal world it would even recognise this is an equivalent use of 
enable_if

#include <type_traits>

template<typename T>
struct some_trait : std::false_type { };

template<typename T>
struct a_pony
: std::enable_if<some_trait<T>::value>
{ };

template<typename T,
         typename Requires = typename a_pony<T>::type>
void foo() { }

int main()
{
    foo<int>();
}

And also recognise my preferred form of using enable_if constraints via alias
templates:

#include <type_traits>

template<typename T>
struct some_trait : std::false_type { };

template<typename T>
    using unicorns
        = typename std::enable_if<some_trait<T>::value>::type;

template<typename T,
         typename Requires = unicorns<T>>
void foo() { }

int main()
{
    foo<int>();
}

(unicorns might be simpler than a_pony since there's no other type involved,
just an alias for enable_if)

-- 
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/20130404/68e2f766/attachment.html>


More information about the llvm-bugs mailing list