Skip to content

Commit

Permalink
Mark unused structured bindings with YANET_GCC_BUG_UNUSED instead of …
Browse files Browse the repository at this point in the history
…void cast

GCC 7.5 version which we have to support for now due to Ubuntu 18 have a bug
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81767) where unused variables in
structured bindings are incorrectly flagged as warnings, even though they
"can't" be used, cause they are not a real variables.

Current code uses `(void)var;` to suppress these warnings, but this approach
is ugly and harder to grep.

This commit removes `(void)var;` statements and replaces it with `YANET_GCC_BUG_UNUSED`

Once we move to a newer GCC version where this bug is fixed,
we can easily remove the that macro as it is much easier to grep and remove
than those void(var) statements
  • Loading branch information
ol-imorozko committed Nov 28, 2024
1 parent 07f3977 commit 01422b7
Show file tree
Hide file tree
Showing 48 changed files with 380 additions and 365 deletions.
6 changes: 3 additions & 3 deletions autotest/autotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ eResult tAutotest::init(const std::string& binaryPath,
bool dumpPackets,
const std::vector<std::string>& configFilePaths)
{
(void)binaryPath;
YANET_GCC_BUG_UNUSED(binaryPath);
this->dumpPackets = dumpPackets;
this->configFilePaths = configFilePaths;

Expand Down Expand Up @@ -871,10 +871,10 @@ bool tAutotest::step_checkCounters(const YAML::Node& yamlStep)
auto fwList = controlPlane.getFwList(common::icp::getFwList::requestType::static_rules_original);
for (auto& [ruleno, rules] : fwList)
{
(void)ruleno;
YANET_GCC_BUG_UNUSED(ruleno);
for (auto& [id, counter, text] : rules)
{
(void)text;
YANET_GCC_BUG_UNUSED(text);
counters[id] = counter;
}
}
Expand Down
10 changes: 5 additions & 5 deletions cli/balancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void service(std::string module_string,
{
const auto& [virtual_ip, proto, virtual_port] = service_key;
const auto& [scheduler, version, nap_connections, packets, bytes] = service_value;
(void)nap_connections; ///< @todo: DELETE
YANET_GCC_BUG_UNUSED(nap_connections); ///< @todo: DELETE

auto proto_string = controlplane::balancer::from_proto(proto);

Expand All @@ -97,7 +97,7 @@ void service(std::string module_string,
uint32_t connections = 0;
for (auto& [socket_id, service_connections] : balancer_service_connections)
{
(void)socket_id;
YANET_GCC_BUG_UNUSED(socket_id);

const auto& socket_connections = service_connections[key].value;
if (socket_connections > connections)
Expand Down Expand Up @@ -238,7 +238,7 @@ void real_find(std::string module_string,
uint32_t connections = 0;
for (auto& [socket_id, real_connections] : balancer_real_connections)
{
(void)socket_id;
YANET_GCC_BUG_UNUSED(socket_id);

const auto& socket_connections = real_connections[key].value;
if (socket_connections > connections)
Expand Down Expand Up @@ -320,7 +320,7 @@ void state(std::string module,
/// @todo: OPT
for (const auto& [socket_id, services_real_connections] : response)
{
(void)socket_id;
YANET_GCC_BUG_UNUSED(socket_id);

for (const auto& [services_real, connections] : services_real_connections)
{
Expand All @@ -330,7 +330,7 @@ void state(std::string module,

for (const auto& [client_ip, client_port, timestamp_create, timestamp_last_packet, timestamp_gc] : connections)
{
(void)timestamp_gc;
YANET_GCC_BUG_UNUSED(timestamp_gc);

auto it = map.find({client_ip, client_port});
if (it != map.end())
Expand Down
6 changes: 3 additions & 3 deletions cli/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using bus_request_info = std::tuple<std::string, uint64_t, uint64_t>;
inline std::vector<bus_request_info> get_bus_requests(common::sdp::DataPlaneInSharedMemory& sdp_data)
{
auto [requests, errors, durations] = sdp_data.BuffersBus();
(void)errors;
YANET_GCC_BUG_UNUSED(errors);

std::map<common::idp::requestType, std::string> names = {
{common::idp::requestType::updateGlobalBase, "updateGlobalBase"},
Expand Down Expand Up @@ -94,8 +94,8 @@ inline void bus_requests()
inline std::vector<std::pair<std::string, uint64_t>> get_bus_errors(const common::sdp::DataPlaneInSharedMemory& sdp_data)
{
auto [requests, errors, durations] = sdp_data.BuffersBus();
(void)requests;
(void)durations;
YANET_GCC_BUG_UNUSED(requests);
YANET_GCC_BUG_UNUSED(durations);

std::map<common::idp::errorType, std::string> names = {
{common::idp::errorType::busRead, "busRead"},
Expand Down
4 changes: 2 additions & 2 deletions cli/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void allow(const std::string& module,
checkModuleType(decap, "decap");

const auto& [prefixes, inserted] = decap.emplace("ipv6DestinationPrefixes", nlohmann::json::array_t{});
(void)inserted;
YANET_GCC_BUG_UNUSED(inserted);

if (allowPrefix(*prefixes, prefixRaw, announceRaw))
{
Expand Down Expand Up @@ -436,7 +436,7 @@ static void allowAny(const std::string& module,
checkModuleType(nat64, "nat64stateless");

const auto& [prefixes, inserted] = nat64.emplace("nat64_prefixes", nlohmann::json::array_t{});
(void)inserted;
YANET_GCC_BUG_UNUSED(inserted);

if (allowPrefix(*prefixes, prefixRaw, announceRaw))
{
Expand Down
2 changes: 1 addition & 1 deletion cli/develop.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class tsc_monitoring_t

for (const auto& [core, socket, ipc_key, offset] : response)
{
(void)socket;
YANET_GCC_BUG_UNUSED(socket);
if (ipc_cache.find(ipc_key) == ipc_cache.end())
{
auto shmid = shmget(ipc_key, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void printUsage()
printf("usage:\n");
for (const auto& [command, args, function] : commands)
{
(void)function;
YANET_GCC_BUG_UNUSED(function);

if (command.empty())
{
Expand Down
4 changes: 2 additions & 2 deletions cli/memory_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void show()

const auto response = dataplane.memory_manager_stats();
const auto& [response_memory_group, response_objects] = response;
(void)response_memory_group;
YANET_GCC_BUG_UNUSED(response_memory_group);

table_t table;
table.insert("name",
Expand Down Expand Up @@ -55,7 +55,7 @@ void group()

for (const auto& [name, socket_id, current] : response_objects)
{
(void)socket_id;
YANET_GCC_BUG_UNUSED(socket_id);

currents[name] = std::max(currents[name].value,
current);
Expand Down
2 changes: 1 addition & 1 deletion cli/rib.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void get(const std::string& vrf,
{
const auto& [protocol, peer, table_name, path_information] = nexthop_key;
const auto& [nexthop, labels, origin, med, aspath, communities, large_communities, local_preference] = nexthop_value;
(void)prefix;
YANET_GCC_BUG_UNUSED(prefix);

table.insert(vrf,
priority,
Expand Down
4 changes: 2 additions & 2 deletions cli/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void get(const std::string& route_name,
for (const auto& item : response)
{
const auto& [ingress_physical_ports, prefix, nexthop, egress_interface, labels] = item;
(void)prefix;
YANET_GCC_BUG_UNUSED(prefix);

table.insert(ingress_physical_ports,
nexthop.is_default() ? std::string("") : nexthop.toString(),
Expand Down Expand Up @@ -190,7 +190,7 @@ void get(const std::string& route_name,
for (const auto& item : response)
{
const auto& [ingress_physical_ports, prefix, nexthop, label, egress_interface, peer, weight_percent] = item;
(void)prefix;
YANET_GCC_BUG_UNUSED(prefix);

double percent = (double)100.0 * weight_percent;

Expand Down
2 changes: 1 addition & 1 deletion cli/show.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ static void list_fw_rules(unsigned int mask, bool list)
{
if (list)
{
(void)counter;
YANET_GCC_BUG_UNUSED(counter);
table.insert(id, ruleno, label, text);
}
else
Expand Down
18 changes: 9 additions & 9 deletions cli/telegraf.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ void ports_stats()
{
interface::dataPlane dataplane;
const auto [ports_cfg, cores_cfg, values] = dataplane.getConfig();
(void)cores_cfg;
(void)values;
YANET_GCC_BUG_UNUSED(cores_cfg);
YANET_GCC_BUG_UNUSED(values);

const std::vector<std::tuple<const char*, common::idp::port_stats_t>> ports_stats_per_type{
{"port", dataplane.get_ports_stats()},
Expand All @@ -40,9 +40,9 @@ void ports_stats()
for (const auto& [port_id, stats] : ports_stats)
{
const auto& [interface_name, socket_id, eth_addr, pci] = ports_cfg.at(port_id);
(void)socket_id;
(void)eth_addr;
(void)pci;
YANET_GCC_BUG_UNUSED(socket_id);
YANET_GCC_BUG_UNUSED(eth_addr);
YANET_GCC_BUG_UNUSED(pci);
const auto& [rx_packets, rx_bytes, rx_errors, rx_drops, tx_packets, tx_bytes, tx_errors, tx_drops] = stats;

printf("%s,physicalPortName=%s "
Expand Down Expand Up @@ -453,7 +453,7 @@ void dregress()
std::map<common::community_t, std::string> communities;
for (const auto& [community, peer_link_orig] : communities_orig)
{
(void)peer_link_orig;
YANET_GCC_BUG_UNUSED(peer_link_orig);

uint32_t link_id = 0;

Expand Down Expand Up @@ -588,7 +588,7 @@ void other()
const auto& [flagFirst, workers, ports] = controlPlane.telegraf_other();
const auto rib_summary = controlPlane.rib_summary();
const auto limit_summary = controlPlane.limit_summary();
(void)flagFirst;
YANET_GCC_BUG_UNUSED(flagFirst);

for (const auto& workerIter : workers)
{
Expand Down Expand Up @@ -667,7 +667,7 @@ void service()

for (const auto& [virtual_ip, proto, virtual_port, nap_connections, packets, bytes, real_disabled_packets, real_disabled_bytes] : services)
{
(void)nap_connections;
YANET_GCC_BUG_UNUSED(nap_connections);

common::idp::balancer_service_connections::service_key_t key = {module_id,
virtual_ip,
Expand All @@ -677,7 +677,7 @@ void service()
uint32_t connections = 0;
for (auto& [socket_id, service_connections] : balancer_service_connections)
{
(void)socket_id;
YANET_GCC_BUG_UNUSED(socket_id);

const auto& socket_connections = service_connections[key].value;
if (socket_connections > connections)
Expand Down
8 changes: 4 additions & 4 deletions common/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ struct ctree
const std::vector<std::string>& key_names,
const std::function<void(const std::string& key, const values_t&)>& callback) const
{
(void)key_index;
(void)key_names;
YANET_GCC_BUG_UNUSED(key_index);
YANET_GCC_BUG_UNUSED(key_names);

callback(key, values);
}
Expand Down Expand Up @@ -195,7 +195,7 @@ struct ctree
{
for (auto& [next_counter, next_node] : next)
{
(void)next_counter;
YANET_GCC_BUG_UNUSED(next_counter);
delete next_node;
}
}
Expand Down Expand Up @@ -271,7 +271,7 @@ struct ctree
{
for (const auto& [next_counter, next_node] : next)
{
(void)next_counter;
YANET_GCC_BUG_UNUSED(next_counter);
static_cast<node_t<next_counters_T...>*>(next_node)->convert_update(next_converts...);
}
}
Expand Down
17 changes: 16 additions & 1 deletion common/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@
#include <vector>


#define YANET_UNUSED [[maybe_unused]]
/**
* GCC 7.5 version which we have to support for now due to Ubuntu 18 have a bug
* (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81767) where unused variables
* in structured bindings are incorrectly flagged as warnings, even though
* they "can't" be used, cause they are not a real variables.
*
* Previously, code used `(void)var;` to suppress these warnings, but this
* approach was ugly and harder to grep.
*
* One should use this macro in structured bindings to mark unused bunding.
*
* Once we move to a newer GCC version where this bug is fixed,
* we can easily remove this macro as it is much easier to grep and remove
* than those void(var) statements.
*/
#define YANET_GCC_BUG_UNUSED(arg) (void)(arg)

#define YANET_LOG_PRINT(msg, args...) fprintf(stdout, msg, ##args)

Expand Down
6 changes: 3 additions & 3 deletions common/refarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class refarray_t
}

auto& [refcount, id] = it->second;
(void)id;
YANET_GCC_BUG_UNUSED(id);

refcount++;

Expand Down Expand Up @@ -106,7 +106,7 @@ class refarray_t

const auto& value = it->second;
auto& [refcount, values_id] = values[value];
(void)values_id;
YANET_GCC_BUG_UNUSED(values_id);

refcount--;
if (refcount)
Expand Down Expand Up @@ -162,7 +162,7 @@ class refarray_t

auto it = values.find(value);
const auto& [refcount, id] = it->second;
(void)refcount;
YANET_GCC_BUG_UNUSED(refcount);

return id;
}
Expand Down
4 changes: 2 additions & 2 deletions controlplane/acl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,10 @@ iface_map_t ifaceMapping(std::map<std::string, controlplane::base::logical_port_

for (const auto& [route_name, route] : routes)
{
(void)route_name;
YANET_GCC_BUG_UNUSED(route_name);
for (const auto& [name, iface] : route.interfaces)
{
(void)name;
YANET_GCC_BUG_UNUSED(name);
ret[iface.aclId].emplace(false, iface.nextModule);
}
}
Expand Down
8 changes: 4 additions & 4 deletions controlplane/acl/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1114,12 +1114,12 @@ struct rule_t
ids.emplace_back(rulep->ruleid);
for (const auto& [name, how] : rulep->ifaces)
{
(void)how; // XXX: we can use in/out filters
YANET_GCC_BUG_UNUSED(how); // XXX: we can use in/out filters
via.insert(name);
}
for (const auto& [direction, tables] : rulep->iface_tables)
{
(void)direction; // XXX: we can use in/out filters
YANET_GCC_BUG_UNUSED(direction); // XXX: we can use in/out filters
for (const auto& tablename : tables)
{
if (configp->m_tables.count(tablename) == 0)
Expand All @@ -1133,15 +1133,15 @@ struct rule_t
const auto& ifnames = std::get<ipfw::tables::ifname_t>(table);
for (const auto& [iface, label] : ifnames)
{
(void)label;
YANET_GCC_BUG_UNUSED(label);
via.insert(iface);
}
}
else
{
YANET_LOG_WARNING("wrong type for interface table %s\n", tablename.data());
}
(void)location;
YANET_GCC_BUG_UNUSED(location);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion controlplane/acl_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void transport_t::distribute()
for (const auto& [key, network_table_group_ids] : variation)
{
const auto& [size, filter_ids] = key;
(void)size;
YANET_GCC_BUG_UNUSED(size);

unsigned int best_layer_id = 0;
auto best_filter_ids_count = (size_t)-1;
Expand Down
Loading

0 comments on commit 01422b7

Please sign in to comment.