public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Visibility warning due to a lambda capture
@ 2021-09-26 19:11 Sam Varshavchik
  0 siblings, 0 replies; only message in thread
From: Sam Varshavchik @ 2021-09-26 19:11 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 2178 bytes --]

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 #2: Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-26 19:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-26 19:11 Visibility warning due to a lambda capture Sam Varshavchik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).