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

            Bug ID: 67358
           Summary: const makes the code behavior changes
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liweifriends at gmail dot com
  Target Milestone: ---

#include <iostream>
#include <map>
#include <string>
using namespace std;

struct LoadModel;

template<typename T>
class Hello
{
public:
    template<typename TLayerOp, typename...TArgs>
    friend void LayerOperation(TLayerOp*,
                               Hello& p_layer,
                               TArgs&&...args)
    {
        cout << 10 << endl;
    }

    friend void LayerOperation(LoadModel*,
                               Hello& p_layer,
                               int& p)
    {
        cout << 20 << endl;
    }
};


int main()
{
    int p;
    Hello<bool> h;
    LayerOperation(static_cast<LoadModel*>(nullptr), h, p);
}

Currently, the code output 20, means the second LayerOperation function is
invoked.
But if I modify its third parameter as follows:

    friend void LayerOperation(LoadModel*,
                               Hello& p_layer,
                               const int& p)
    {
        cout << 20 << endl;
    }

The code will output 10, means the first LayerOperation function is invoked.

Is this a feature or a bug?

Reply via email to