asn1c
asn1c copied to clipboard
Lots of visibility warnings compiling for ldap.asn1.
When compiling code generated from the standard ldap.asn1 there are many warnings in the form;
asn1/SubstringFilter.h:42:10: warning: ‘union SubstringFilter__substrings__substring_u’ declared inside parameter list will not be visible outside of this definition or declaration
42 | union SubstringFilter__substrings__substring_u {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
asn1/asn_SET_OF.h:17:16: note: in definition of macro ‘A_SET_OF’
17 | void (*free)(type *); \
| ^~~~
In clang, these warnings can be turned off with -Wno-visibility, but gcc doesn't seem to have the ability to silence them at all. Perhaps the reason for this is the general wisdom on these warnings is they nearly always indicate a serious problem you can easily fix;
https://stackoverflow.com/questions/37463362/how-do-i-suppress-warning-struct-xxyy-declared-inside-parameter-list/37464511#37464511
In this particular case, the problem seems to be in the following line;
https://github.com/vlm/asn1c/blob/9925dbbda86b436896108439ea3e0a31280a6065/skeletons/asn_SET_OF.h#L22
Note that it declares a function pointer that takes an argument of type *, where type is an argument to the A_SET_OF() macro. This normally works fine when type is a simple type or even struct reference. However, in the asn1c generated SubstringFilter.h file it gets called (via A_SEQUENCE_OF()) with the following literal argument for type;
A_SET_OF(struct SubstringFilter__substrings__substring {
SubstringFilter__substrings__substring_PR present;
union SubstringFilter__substrings__substring_u {
AssertionValue_t initial;
AssertionValue_t any;
AssertionValue_t final;
/*
* This type is extensible,
* possible extensions are below.
*/
} choice;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
} )
This is a complicated struct definition containing another union definition. The C compiler sees this as a type definition inside a function argument that it has no prior definition for, hence the warning.
Using type definitions as the argument type to a function like this is pretty questionable. It would be much better to define the type earlier, possibly using a typedef, and just pass the type name (declaration?) to A_SET_OF().
For the record, the corresponding asn1 definition that causes this is;
SubstringFilter ::= SEQUENCE {
type AttributeDescription,
substrings SEQUENCE SIZE (1..MAX) OF substring CHOICE {
initial [0] AssertionValue, -- can occur at most once
any [1] AssertionValue,
final [2] AssertionValue } -- can occur at most once
}
So it appears to happen whenever there is a SEQUENCE with an inline definition, instead of referencing another existing asn1 definition. This suggests a workaround would be to change the asn1 definition and add another definition instead of inlining it. However, in my case I'm using the upstream LDAP asn1 definition and would prefer not to modify it.