Visibility warning due to a lambda capture

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This looks related to bug 80947 and bug 85646, except that no compiler flags are required:

$ g++ -c -o /tmp/t.o /tmp/t.C
/tmp/t.C: In member function ‘void some_class::call_funcs(const hidden_struct&, const default_struct&)’: /tmp/t.C:28:31: warning: ‘some_class::call_funcs(const hidden_struct&, const default_struct&)::<lambda()>’ declared with greater visibility than the type of its field ‘some_class::call_funcs(const hidden_struct&, const default_struct&)::<lambda()>::<h capture>’ [-Wattributes]
  28 |                            [&h]
     |                               ^


Reproducer:

==========================================================================
#include <functional>

struct __attribute__((visibility("hidden"))) hidden_struct;

struct default_struct;

void func_hidden(const hidden_struct &);

void func_default(const default_struct &);

class some_class {

public:

	void do_nothing(const std::function<void ()>)
	{
	}

	void call_funcs(const hidden_struct &h,
			const default_struct &d)
	{

		// This pragma makes no difference:

#pragma GCC visibility push(hidden)

		do_nothing(
			   [&h]
			   {
#if 0
				   // Diagnostic with default capture:
				   //
				   func_hidden(h);
				   //
				   // No diagnostic:
				   //
				   // func_default(d);
#endif
			   });

#pragma GCC visibility pop

	}
};

==========================================================================

This is with gcc 11.2.1.

The pragma were a vain attempt to make the lambda hidden. I get the same diagnostic with a default capture.

The problem seems to me that the lambda's anonymous class gets the default visibility, and the diagnostic gets issued due to the type of the captured object's class member having hidden visibility.

Am I missing some way to make the resulting anonymous class have hidden visibility? I tried explicit __attribute__ declarations (in the lambda's vicinity), it made no difference. I would think that the pragma would do the trick, but it made no difference either. -fvisibility-inlines-hidden doesn't help either.

Attachment: pgp6nHXNEuTeh.pgp
Description: PGP signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux