Skip to content

documentation: coding style guidance for [[maybe_unused]]

As a follow-up to commit 0e685cbd, I would like to update the coding style with recommended usage.

I would also like to propose a change to how unused parameters are being handled in functions and methods, which is why I put the 'Draft:' label on this. I am proposing that we leave definitely unused parameters as unnamed parameters in the implementation, while keeping them as named and Doxygen-documented parameters in the headers (but noting such parameters as unused).

There are two reasons for this:

  1. makes the code more succinct/readable (IMO), and is technically more correct (the parameter is not 'maybe unused', it is definitely unused)
  2. I found that Doxygen produced fewer warnings

Regarding the second reason, a newly introduced warning after commit 0e685cbd is the following:

ns-3-dev/src/uan/model/uan-net-device.cc:278: warning: no uniquely matching class member found for
  Address ns3::UanNetDevice::GetMulticast([[maybe_unused]] Ipv4Address multicastGroup) const
Possible candidates:
  'virtual Address ns3::UanNetDevice::GetMulticast(Ipv4Address multicastGroup) const' at line 135 of file /ns-3-dev/src/uan/model/uan-net-device.h
  'virtual Address ns3::UanNetDevice::GetMulticast(Ipv6Address addr) const' at line 136 of file /ns-3-dev/src/uan/model/uan-net-device.h

If we change the code to:

 Address
-UanNetDevice::GetMulticast ([[maybe_unused]] Ipv4Address multicastGroup) const
+UanNetDevice::GetMulticast (Ipv4Address) const
 {
   return m_mac->GetBroadcast ();
 }

 Address
-UanNetDevice::GetMulticast (Ipv6Address addr) const
+UanNetDevice::GetMulticast (Ipv6Address) const
 {
   return m_mac->GetBroadcast ();
 }

this warning disappears.

Comments before I proceed with a full patch?

Edited by Tom Henderson

Merge request reports

Loading