[SERVER-39879] Fix unique_function constructor selection issues Created: 27/Feb/19  Updated: 29/Oct/23  Resolved: 27/Jun/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.3.1

Type: Bug Priority: Major - P3
Reporter: Benjamin Caimano (Inactive) Assignee: Andrew Morrow (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Dev Tools 2019-03-25, Dev Tools 2019-04-08, Dev Tools 2019-04-22, Dev Tools 2019-06-03, Dev Tools 2019-07-01
Participants:

 Description   

It appears that code of the following form segfaults due to recursion

unique_function<void(void)> _fun;
auto assignFun(unique_function<void(void)> fun){
    _fun = fun;
}

This appears to be due to the fact that the unique_function ctor resolves to have a non-const lvalue reference parameter of unique_function, which is valid because of the templated ctor.



 Comments   
Comment by Benjamin Caimano (Inactive) [ 27/Jun/19 ]

Closing this issue on request. If you run into the is_constructible related issues described in these comments, please submit a follow-on ticket.

Comment by Githook User [ 27/May/19 ]

Author:

{'name': 'Ben Caimano', 'email': 'ben.caimano@10gen.com'}

Message: SERVER-39879 Fix unique_function constructor selection issues
Branch: master
https://github.com/mongodb/mongo/commit/452c7f88eb3aa4da8637b875006f82e04d496865

Comment by A. Jesse Jiryu Davis [ 21/May/19 ]

Should this be assigned to adam.martin again for merging?

Comment by Benjamin Caimano (Inactive) [ 13/Mar/19 ]

Apparently, there is an additional related issue wherein there are compilation issues when using is_constructible<unique_function<>>. This seems to come from the ordering of enable_if statements in the templated ctor. Essentially, when resolving __is_move_constructible we hit the template and attempt to use is_move_constructible. (See godbolt concept example here.)

It appears that the current order is:

  • is_same_v
  • is_move_constructible_v
  • is_invocable_v
Generated at Thu Feb 08 04:53:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.