google/j2objc

a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]

mungler opened this issue · 7 comments

Hi,

We've been using j2objc for many years to great effect. We've recently started noticing this warning and i'm getting complaints from our iOS developers about it. It seems to reference to a great many j2objc generated classes, and is always:

"a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]". An example from our codebase:

J2OBJC_CLASS_TYPE_LITERAL_SOURCE(ASWv2AbstractArticle)

And another:

ASWPresentersWebPublicEventsPresenter_Resources *new_ASWPresentersWebPublicEventsPresenter_Resources_init() {
J2OBJC_NEW_IMPL(ASWPresentersWebPublicEventsPresenter_Resources, init)
}

Both of these flag the warning in xcode.

Any advice? Is this a case of 'just turn off the strict-prototypes option', or is there something that can be done to address this?

Thanks!

That's surprising, as j2objc should be generating all declarations before use. The J2OBJC_CLASS_TYPE_LITERAL_SOURCE error is very strange, as it's included in every .m file, and should match a J2OBJC_TYPE_LITERAL_HEADER that is either in the same file (if the type is private) or in the associated .h file.

One possible problem is if you are using #import with j2objc-generated headers instead of #include. #include is necessary when a generated header has multiple types which refer to each other (an "include cycle"). We minimize the need for this by declaring @class and @protocol declarations where needed, but sometimes both types need to be fully declared, so j2objc generates segmented headers. Segmented headers in a way split a single header file into multiple ones that can be separately included, so #import can't be used since only one segment will be read.

Are you only seeing this in the Xcode UI, and not in a build log? If so, then Xcode may be confused by segmented headers.

Hi Tom, thanks for the speedy response. I'll check out #include versus #import - looks like we may be doing this wrong, though a quick change to include doesn't seem to result in fewer warnings, so far.

We use j2objc to convert a java library to a static library project in xcode. The main header file for our library currently looks like this - is there some overarching import/include i should be doing?


#include <Foundation/Foundation.h>

#include "J2ObjC_header.h"

#include "java/lang/Integer.h"
#include "java/lang/Boolean.h"
#include "java/lang/Long.h"
#include "java/lang/Double.h"
#include "java/math/BigDecimal.h"
#include "java/util/Date.h"
#include "java/util/List.h"
#include "java/util/AbstractList.h"
#include "java/util/ArrayList.h"
#include "java/util/Collection.h"
#include "java/util/AbstractMap.h"
#include "java/util/Map.h"
#include "java/util/Set.h"
#include "java/io/File.h"
#include "IOSClass.h"
#include "IOSPrimitiveArray.h"

Its very strange, actually, because taking another example:

ASWPresentersStep2AddYourIntroductionPresenter *new_ASWPresentersStep2AddYourIntroductionPresenter_init() {
...
}

Xcode highlights in yellow the () after 'init' with the usual warning, but I can see the header is declared with (void), which is, as far as I can gather, correct:

FOUNDATION_EXPORT ASWPresentersStep2AddYourIntroductionPresenter *new_ASWPresentersStep2AddYourIntroductionPresenter_init(void) NS_RETURNS_RETAINED;

For what its worth, I changed all imports to includes for generated code in our library project and the number of warnings did not drop.

Screenshot 2023-07-18 at 19 15 55

Interesting.. in this case, its offering to 'fix' the issue by injecting (void) in the .m file.

My guess is that Xcode is now getting confused by how j2objc's generates declarations. If you have the time, please try applying all the Xcode fixes and then diffing the generated sources to see what it changed. If we can tweak j2objc's output to make Xcode happy (without breaking anything), we should do that. Also, what version of Xcode are you using?

Thanks Tom. The Xcode version is reported as Version 14.3.1 (14E300c)

We have more than 2000 warnings currently, so i'm not sure I can set about applying all of the fixes its suggesting. From what i've seen its mostly injecting (void) in places where the .m files have (). However, the relevant generated headers have the correct form with (void) so i'm not even sure why its suggesting these changes.

Some of the other changes its suggesting are... well, odd:

Screenshot 2023-07-18 at 21 20 45

Closing this as I think this is due to the weird way i'm using the headers from the j2objc dist along with the JRE framework bundle.