Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Offset of on non-standard-layout type" warning on new SDK (C++) in Xcode #1

Open
AlexHarker opened this issue Sep 19, 2021 · 3 comments

Comments

@AlexHarker
Copy link
Contributor

AlexHarker commented Sep 19, 2021

Since moving to max-sdk-base (from the old max-sdk, prior to this separation) I've been getting these warnings about macros like:

CLASS_ATTR_SYM

in Xcode where the max object is a C++ object (I'm not using the min-api I have my own C++ wrapper). The warning does not occur for exactly the same code if I switch back to the old SDK, so it's related to the SDK, and not Xcode version/compiler etc. I cannot find any relevant pragmas that would have previously been suppressing the warning, nor do my types have any virtual methods.

Everything still works as expected, but it is a bit tedious - do you have any pointers for why this might have changed and if I can suppress the warnings?

@AlexHarker
Copy link
Contributor Author

Ah - I see that the definition of calcoffset has changed from:

#define calcoffset(x,y) ((t_ptr_int)(&(((x *)0L)->y)))

to

#define calcoffset(x,y) offsetof(x, y)

(where offsetof() will map to __builtin_offsetof).

That explains why it happens, so I guess this may cause warnings for anyone making externals as C++ objects, whether using min-api or not.

@superbigio
Copy link

Yes, it does cause warnings for all the CLASS_ATTR macros (since they all use the calcoffset macro under the hood) which is harmless but very annoying...
It could be trivially solved by declaring:

#define calcoffset(x,y) ((t_ptr_int)offsetof(x, y))

But I don't know if the C74 folks will ever make this change, and I don't feel like spending the time to create a pull request that might be ignored. As you can clearly see C74 is not very responsive to this kind of SDK related bugs.

On a more general note the habit of using unsigned integers for sizes and quantities is absolutely wrong.
Unfortunately the C++ std library declares size_t as unsigned and therefore it's hard to escape the pitfall.

@AlexHarker
Copy link
Contributor Author

FWIW - I am currently using -Wno-invalid-offsetof in my configs which suppresses the warning. The warning is technically correct due to the very narrow definition of a POD type in the C++ standard, but in practice the types I am using are safe to use offsetof() on.

I'm not sure of the relevance of unsigned integers to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants