'Error: declaration of ‘freefunc’ shadows a global declaration

While building application using openssl 1.1.1d I am getting below error,

I know C++ but not an expert. Spent lot of time but still did not get any clue. Can someone please help me to identify the root cause.

In file included from /usr/local/ssl/include/openssl/crypto.h:23:0,
                 from /usr/local/ssl/include/openssl/bio.h:20,
                 from /usr/local/ssl/include/openssl/err.h:21,
                 from main.cpp:41:
/usr/local/ssl/include/openssl/safestack.h: In function ‘void sk_OPENSSL_STRING_pop_free(stack_st_OPENSSL_STRING*, sk_OPENSSL_STRING_freefunc)’:
/usr/local/ssl/include/openssl/safestack.h:84:105: error: declaration of ‘freefunc’ shadows a global declaration [-Werror=shadow]
     static ossl_unused ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \
                                                                                                         ^
/usr/local/ssl/include/openssl/safestack.h:129:42: note: in expansion of macro ‘SKM_DEFINE_STACK_OF’
 # define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2)
                                          ^
/usr/local/ssl/include/openssl/safestack.h:159:1: note: in expansion of macro ‘DEFINE_SPECIAL_STACK_OF’
 DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
 ^
In file included from /builddir/.iwmake/repository/expanded/com/tripwire/ip360/dp/stackless/python/dp-stackless-python/2.7.16.tw1.bfeature-centos7_support_OpenSSL_1.1.1d_for_profiler_scanning.r20200413140649-ef994e5.b22//include/python2.7/Python.h:91:0,
                 from main.cpp:19:
/builddir/.iwmake/repository/expanded/com/tripwire/ip360/dp/stackless/python/dp-stackless-python/2.7.16.tw1.bfeature-centos7_support_OpenSSL_1.1.1d_for_profiler_scanning.r20200413140649-ef994e5.b22//include/python2.7/object.h:324:16: error: shadowed declaration is here [-Werror=shadow]
 typedef void (*freefunc)(void *);



Solution 1:[1]

This is a little war between developers/programmers and language advocates.

Either way: the python library declares a function pointer type :

typedef void (*freefunc)(void *);

Which because openssl has a formal parameter in multiple function definitions named freefunc can with some other misfeatures cause shadowing of the Python freefunc. Multiple solutions exists:

  1. don't use -Wshadow together with -Werror, or
  2. use Wshadow but use pragmas where things goes boom to declare that the usage is OK, or
  3. DON'T name formal parameters (which can be seen as a crutch) - which goes boom against coding standards etc... Almost all the openssl developers is against removing names of formal parameters in function prototypes.
  4. in this specific case force Python developers to rename it's type freefunc.

Read https://mta.openssl.org/pipermail/openssl-users/2020-June/012539.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stefan Skoglund