Bug 1149294 - template argument deduction/substitution fails when default argument is lambda
Summary: template argument deduction/substitution fails when default argument is lambda
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Developer Toolset
Classification: Red Hat
Component: gcc
Version: DTS 3.0 RHEL 7
Hardware: All
OS: Linux
medium
medium
Target Milestone: alpha
: 3.0
Assignee: Jakub Jelinek
QA Contact: Miroslav Franc
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-10-03 16:41 UTC by Miroslav Franc
Modified: 2016-02-01 02:29 UTC (History)
7 users (show)

Fixed In Version: devtoolset-3-gcc-4.9.2-5.el6
Doc Type: Bug Fix
Doc Text:
No description necessary
Clone Of:
Environment:
Last Closed: 2015-04-23 07:53:48 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2015:0880 0 normal SHIPPED_LIVE devtoolset-3-gcc bug fix and enhancement update 2015-04-23 11:53:28 UTC

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


Note You need to log in before you can comment on or make changes to this bug.