Why are two using clauses resolving to the same type seen as ambigious in gcc

Andrew Goedhart :

I have two base classes with using clauses

 class MultiCmdQueueCallback {
  using NetworkPacket  = Networking::NetworkPacket;
  ....
 }


 class PlcMsgFactoryImplCallback {
   using NetworkPacket = Networking::NetworkPacket;
  ....
 }

I then declare a class

class PlcNetwork : 
  public RouterCallback, 
  public PlcMsgFactoryImplCallback, 
  public MultiCmdQueueCallback {
  private:
    void sendNetworkPacket(const NetworkPacket &pdu);
}

the compiler then flags an error reference to 'NetworkPacket' is ambiguous 'sendNetworkPacket(NetworkPacket &... '

Now both 'using clauses' resolve to the same underlying class Networking:NetworkPacket

and in fact if I replace the method declaration with:

 void sendNetworkPacket(const Networking::NetworkPacket &pdu);

it compiles fine.

Why is the compiler treating each using clause as a distinct type even though they both point to the same underlying type. Is this mandated by the standard or do we have a compiler bug ?

Jarod42 :

Before looking at alias resulting type, (and accessibility)

we look at names

and indeed,

NetworkPacket might be

  • MultiCmdQueueCallback::NetworkPacket
  • or PlcMsgFactoryImplCallback::NetworkPacket

The fact they both point to Networking::NetworkPacket is irrelevant.

We do first name resolution, which results in ambiguity.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=29239&siteId=1