https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947
Bug ID: 80947 Summary: Different visibility for the lambda and its capture list members with -fvisibility=hidden Product: gcc Version: 6.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vladz at scylladb dot com Target Milestone: --- I'm trying to compile a C++14 program using standard g++-6 and g++-7 compilers coming with Ubuntu 16.04: g++-6 (Ubuntu/Linaro 6.3.0-18ubuntu2~16.04) 6.3.0 20170519 g++-7 (Ubuntu 7.1.0-5ubuntu2~16.04) 7.1.0 The error I get with both of them is the same. The issue doesn't reproduce with the g++ (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904 The issue doesn't reproduce when I use -fvisibility=default. The error looks as follows: g++-6 -MD -MT build/release/gms/versioned_value.o -MF build/release/gms/versioned_value.o.d -std=gnu++1y -g -Wall -Werror -fvisibility-inlines-hidden -fvisibility=hidden -pthread -I/home/vladz/work/urchin/seastar -I/home/vladz/work/urchin/seastar/fmt -I/home/vladz/work/urchin/seastar/build/release/gen -march=nehalem -fconcepts -Ifmt -DBOOST_TEST_DYN_LINK -Wno-overloaded-virtual -DFMT_HEADER_ONLY -DHAVE_GCC6_CONCEPTS -DHAVE_HWLOC -DHAVE_NUMA -DHAVE_LZ4_COMPRESS_DEFAULT -O2 -I/usr/include/jsoncpp -DBOOST_TEST_DYN_LINK -Wno-maybe-uninitialized -Wno-tautological-compare -Wno-missing-braces -Wno-error=deprecated-declarations -DHAVE_LIBSYSTEMD=1 -I. -I build/release/gen -I seastar -I seastar/build/release/gen -c -o build/release/gms/versioned_value.o gms/versioned_value.cc In file included from ./utils/exponential_backoff_retry.hh:25:0, from ./sstables/compaction_manager.hh:32, from ./database.hh:67, from ./repair/repair.hh:31, from ./message/messaging_service.hh:34, from gms/versioned_value.cc:39: /home/vladz/work/urchin/seastar/core/sleep.hh: In instantiation of ‘struct seastar::sleep(std::chrono::duration<_Rep, _Period>)::sleeper::sleeper(std::chrono::duration<_Rep, _Period>) [with Clock = std::chrono::_V2::steady_clock; Rep = long int; Period = std::ratio<1l, 1000l>]::<lambda()>’: /home/vladz/work/urchin/seastar/core/sleep.hh:48:47: required from ‘seastar::sleep(std::chrono::duration<_Rep, _Period>)::sleeper::sleeper(std::chrono::duration<_Rep, _Period>) [with Clock = std::chrono::_V2::steady_clock; Rep = long int; Period = std::ratio<1l, 1000l>]’ /home/vladz/work/urchin/seastar/core/sleep.hh:52:5: required from ‘seastar::future<> seastar::sleep(std::chrono::duration<_Rep, _Period>) [with Clock = std::chrono::_V2::steady_clock; Rep = long int; Period = std::ratio<1l, 1000l>]’ ./utils/exponential_backoff_retry.hh:45:36: required from here /home/vladz/work/urchin/seastar/core/sleep.hh:48:24: error: ‘seastar::sleep(std::chrono::duration<_Rep, _Period>)::sleeper::sleeper(std::chrono::duration<_Rep, _Period>) [with Clock = std::chrono::_V2::steady_clock; Rep = long int; Period = std::ratio<1l, 1000l>]::<lambda()>’ declared with greater visibility than the type of its field ‘seastar::sleep(std::chrono::duration<_Rep, _Period>)::sleeper::sleeper(std::chrono::duration<_Rep, _Period>) [with Clock = std::chrono::_V2::steady_clock; Rep = long int; Period = std::ratio<1l, 1000l>]::<lambda()>::<this capture>’ [-Werror=attributes] : tmr([this] { done.set_value(); }) ^ cc1plus: all warnings being treated as errors Error message implies that the visibility of the lambda in question is greater than the visibility of the capture list value "this". Since lambdas are translated into the classes with the operator()(...) and (it seems like) captured values are translated into the fields of this class it looks like for some reason the visibility of that class is higher than the one of those fields. Another workaround that would make the error go away is to explicitly use the __attribute__ ((visibility ("hidden"))) or __attribute__ ((visibility ("default"))) for the sleeper struct. Attached is an *.ii value generated by g++-6