[LLVMbugs] [Bug 18740] New: Unhelpful error message when attempting to deduce an initializer list in a template context

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Feb 5 05:35:50 PST 2014


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

            Bug ID: 18740
           Summary: Unhelpful error message when attempting to deduce an
                    initializer list in a template context
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: matthew.chaplain at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I have the following code:

-----

#include <vector>

#define RETURNS(...) -> decltype((__VA_ARGS__)) { return (__VA_ARGS__); }

template <typename This, typename... Args>
auto fun(This &&this_, Args&&... args)
RETURNS(this_.fun(std::forward<Args>(args)...))

struct X
{
    void fun(std::vector<int> v) {}
};

int main()
{
    X x;
    fun(x, {1, 2, 3});
}

-----

When compiling, this yields the following errors:

-----

subst.cpp:16:5: error: no matching function for call to 'fun'
    fun(x, {1, 2, 3});
    ^~~
subst.cpp:6:6: note: candidate template ignored: substitution failure [with
This
      = X &, Args = <>]: too few arguments to function call, single argument
'v'
      was not specified
auto fun(This &&this_, Args&&... args)
RETURNS(this_.fun(std::forward<Args>(args)...))
     ^                                                                         
    ~
1 error generated.

-----

As I understand (from the discussion in
http://stackoverflow.com/questions/21573808/using-initializer-lists-with-variadic-templates),
the initializer list could not be deduced.  This is not clear in the message,
however, especially with the (IMO) misleading "Args = <>".

Note: reversing the order of declaration of fun<> and struct X instead yields
the following equally misleading error message (because yes it was, right
there!)

-----

subst.cpp:17:5: error: no matching function for call to 'fun'
    fun(x, {1, 2, 3});
    ^~~
subst.cpp:12:6: note: candidate template ignored: substitution failure [with
      This = X &, Args = <>]: too few arguments to function call, single
      argument 'v' was not specified
auto fun(This &&this_, Args&&... args)
RETURNS(this_.fun(std::forward<Args>(args)...))
     ^                                                                         
    ~
1 error generated.

-----

-- 
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/20140205/35ad8f2a/attachment.html>


More information about the llvm-bugs mailing list