From a341309c177f20581705cc0c9d2052d32c5800e1 Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Thu, 10 Feb 2022 09:10:40 -0800 Subject: [PATCH] Fix build issues with gcc 9 (#1090) * Remove redundant moves in return statements With recent g++ versions: ../include/bm/bm_sim/queueing.h:780:24: error: redundant move in return statement [-Werror=redundant-move] 780 | return std::move(fn); | ^ ../include/bm/bm_sim/queueing.h:780:24: note: remove 'std::move' call cc1plus: all warnings being treated as error While copy elision is not possible when retruning a function parameter, if the other conditions for NVO are met, a move operation should be used. The std::move doesn't cause the compiler to perform worse (unlike for RVO), but it is redundant. * Do not treat deprecated-declarations warnings as errors When compiling code which depends on the generated Protobuf code for P4Runtime. * Fix linking for example program in simple_switch_grpc/tests Linking was broken after Ubuntu 20.04 / gcc 9 upgrade. Not sure exactly why but removing some unused library dependencies can resolve the issue ("undefined reference" for PI symbols). --- include/bm/bm_sim/queueing.h | 4 ++-- targets/simple_switch_grpc/tests/Makefile.am | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/bm/bm_sim/queueing.h b/include/bm/bm_sim/queueing.h index e084a1226..225eb29b5 100644 --- a/include/bm/bm_sim/queueing.h +++ b/include/bm/bm_sim/queueing.h @@ -777,7 +777,7 @@ class QueueingLogicPriRL { Function for_each_q(size_t queue_id, Function fn) { auto &q_info = get_queue(queue_id); for (auto &q_info_pri : q_info) fn(q_info_pri); - return std::move(fn); + return fn; } template @@ -785,7 +785,7 @@ class QueueingLogicPriRL { auto &q_info = get_queue(queue_id); auto &q_info_pri = q_info.at(priority); fn(q_info_pri); - return std::move(fn); + return fn; } struct SetCapacityFn { diff --git a/targets/simple_switch_grpc/tests/Makefile.am b/targets/simple_switch_grpc/tests/Makefile.am index 5fd63151e..0ca016b67 100644 --- a/targets/simple_switch_grpc/tests/Makefile.am +++ b/targets/simple_switch_grpc/tests/Makefile.am @@ -3,6 +3,9 @@ ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4 # Ensures that gtest has been built SUBDIRS = ../../../third_party +# for deprecated Protobuf fields +AM_CXXFLAGS += -Wno-error=deprecated-declarations + AM_CPPFLAGS += \ -isystem $(top_srcdir)/../../third_party/gtest/include \ -I$(top_srcdir) \ @@ -31,6 +34,7 @@ check_PROGRAMS = example test_gtest common_source = utils.h utils.cpp base_test.h base_test.cpp example_SOURCES = example.cpp utils.h utils.cpp + test_gtest_SOURCES = \ $(common_source) main.cpp \ test_basic.cpp test_grpc_dp.cpp test_packet_io.cpp \ @@ -45,7 +49,11 @@ if WITH_SYSREPO test_gtest_SOURCES += test_gnmi.cpp endif -LDADD = \ +example_LDADD = \ +-lpiprotogrpc -lpiprotobuf \ +$(PROTOBUF_LIBS) $(GRPC_LIBS) + +test_gtest_LDADD = \ $(top_builddir)/libsimple_switch_grpc.la \ $(top_builddir)/../simple_switch/libsimpleswitch.la \ -lpiprotogrpc -lpiprotobuf \