Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1149294

Summary: template argument deduction/substitution fails when default argument is lambda
Product: Red Hat Developer Toolset Reporter: Miroslav Franc <mfranc>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact: Miroslav Franc <mfranc>
Severity: medium Docs Contact:
Priority: medium    
Version: DTS 3.0 RHEL 7CC: kanderso, law, mcermak, mfranc, mnewsome, mpolacek, ohudlick
Target Milestone: alpha   
Target Release: 3.0   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: devtoolset-3-gcc-4.9.2-5.el6 Doc Type: Bug Fix
Doc Text:
No description necessary
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-04-23 07:53:48 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Miroslav Franc 2014-10-03 16:41:39 UTC
Description of problem:

This is related to bug 982324 and it appears to be a regression.

The testcase from the bug above:
---
#include <functional>

class A {
  typedef std::function<int()> Func;
  Func f_;
public:
  template<class T = Func> A(const T& f = []() { return 0; }) : f_(f) {}
};

int main(int argc, char* argv[]) {
  A a;
}
---

I cannot find anything wrong with it, if I put function pointer or handmade functor instead of lambda as a default parameter, it seems to work.


Version-Release number of selected component (if applicable):
devtoolset-3-gcc-c++-4.9.1-10



Steps to Reproduce:
1.  g++ -g  -std=c++11 test.h


Actual results:
test.h:7:46: error: default argument for template parameter for class enclosing ‘A::<lambda>’
   template<class T = Func> A(const T& f = []() { return 0; }) : f_(f) {}
                                              ^
test.h: In function ‘int main(int, char**)’:
test.h:11:5: error: no matching function for call to ‘A::A()’
   A a;
     ^
test.h:11:5: note: candidates are:
test.h:7:28: note: template<class T> A::A(const T&)
   template<class T = Func> A(const T& f = []() { return 0; }) : f_(f) {}
                            ^
test.h:7:28: note:   template argument deduction/substitution failed:
test.h:11:5: note:   couldn't deduce template parameter ‘T’
   A a;
     ^
test.h:3:7: note: A::A(const A&)
 class A {
       ^
test.h:3:7: note:   candidate expects 1 argument, 0 provided
test.h:3:7: note: A::A(A&&)
test.h:3:7: note:   candidate expects 1 argument, 0 provided


Expected results:
it compiles

Comment 1 Marek Polacek 2014-10-03 16:49:42 UTC
Trunk accepts this.  I'm going to bisect this one.

Comment 2 Marek Polacek 2014-10-03 19:11:34 UTC
Fixed by r215477 aka PR c++/62219 fix.  The fix looks easy and has been backported to 4.9 branch; it basically only allows using LAMBDA_FUNCTION_P as a default template argument.

Comment 5 Marek Polacek 2015-01-09 18:59:48 UTC
Fixed.

Comment 9 errata-xmlrpc 2015-04-23 07:53:48 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-0880.html