[llvm-bugs] [Bug 46648] New: template lambda with default value can't be called if passing argument type doesn't match default value type
    via llvm-bugs 
    llvm-bugs at lists.llvm.org
       
    Wed Jul  8 12:40:35 PDT 2020
    
    
  
https://bugs.llvm.org/show_bug.cgi?id=46648
            Bug ID: 46648
           Summary: template lambda with default value can't be called if
                    passing argument type doesn't match default value type
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: iurii.shtykov at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
interactive: https://godbolt.org/z/mM9hY8
code: 
_________________________
#include <string>
using std::literals::operator""s;
int main(){
    auto error_lambda = []<class T = int>(T def = 1) -> T {
        return def;
    };
    error_lambda(1);
    error_lambda("error"s);
    //but it works if default value = 0
    auto good_lambda = []<class T = int>(T def = 0) -> T {
        return def;
    };
    good_lambda(1);
    good_lambda("good"s);
}
_________________________
output:
<source>:10:5: error: no matching function for call to object of type '(lambda
at <source>:5:25)'
    error_lambda("error"s);
    ^~~~~~~~~~~~
<source>:5:25: note: candidate template ignored: substitution failure [with T =
std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char>>]: no viable conversion from 'int' to
'std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char>>'
    auto error_lambda = []<class T = int>(T def = 1) -> T {
                        ^                   ~~~
1 error generated.
Compiler returned: 1
-- 
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/20200708/014cbc05/attachment.html>
    
    
More information about the llvm-bugs
mailing list