https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81311

            Bug ID: 81311
           Summary: An std::ref argument calls copy constructor instead of
                    template constructor in C++17 mode
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pdimov at gmail dot com
  Target Milestone: ---

In the following code:

```
#include <functional>
#include <iostream>

struct function
{
    function()
    {
        std::cout << "function()\n";
    }

    template<class F> function( F )
    {
        std::cout << "function<F>(F)\n";
    }

    function( function const& )
    {
        std::cout << "function(function const&)\n";
    }
};

int main()
{
    function f1;
    function f2( std::ref(f1) );
}
```

g++ 7.1 and 8 with -std=c++1z/17 call the copy constructor, whereas with
-std=c++14 they call the template constructor (as do other compilers in all
language modes.)

Reply via email to