godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.75k stars 577 forks source link

4.0.1 Compliation error "implicit conversion loses integer precision: 'GDExtensionInt'" with XCode and CMake on MacOS M1 #1080

Open PierceLBrooks opened 1 year ago

PierceLBrooks commented 1 year ago

This can be reproduced with the following project... https://github.com/PierceLBrooks/gdextensions

Also, here is an error message log dump sample showing details of the problem that are repeated times due template interactions upon build failure.

CompileC /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/godot-cpp.build/Debug/godot-cpp.build/Objects-normal/arm64/utility_functions.o /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/gen/src/variant/utility_functions.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'godot-cpp' from project 'godot-cpp')
    cd /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -target arm64-apple-macos13.1 -fmessage-length\=80 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit\=0 -fcolor-diagnostics -Wno-trigraphs -fpascal-strings -O3 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -Wno-implicit-fallthrough -DCMAKE_INTDIR\=\"Debug\" -DDEBUG_ENABLED -DDEBUG_METHODS_ENABLED -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -g -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/bin/Debug/include -isystem /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/include -isystem /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/gen/include -isystem /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/gdextension -I/Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/godot-cpp.build/Debug/godot-cpp.build/DerivedSources-normal/arm64 -I/Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/godot-cpp.build/Debug/godot-cpp.build/DerivedSources/arm64 -I/Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/godot-cpp.build/Debug/godot-cpp.build/DerivedSources -F/Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/bin/Debug -fPIC -Wall -Wctor-dtor-privacy -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wwrite-strings -Wimplicit-fallthrough -Wno-ordered-compare-function-pointers -std\=c++17 -Werror -MMD -MT dependencies -MF /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/godot-cpp.build/Debug/godot-cpp.build/Objects-normal/arm64/utility_functions.d --serialize-diagnostics /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/godot-cpp.build/Debug/godot-cpp.build/Objects-normal/arm64/utility_functions.dia -c /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/gen/src/variant/utility_functions.cpp -o /Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/godot-cpp.build/Debug/godot-cpp.build/Objects-normal/arm64/utility_functions.o
/Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/gen/src/variant/utility_functions.cpp:701:74: error: 
      implicit conversion loses integer precision: 'GDExtensionInt'
      (aka 'long long') to 'int' [-Werror,-Wshorten-64-to-32]
  ...___function(&ret, reinterpret_cast<GDExtensionConstVariantPtr *>(args), arg_count);
     ~~~~~~~~~~~                                                             ^~~~~~~~~
/Users/pbrooks/Development/Personal/Games/Friends/Kory/gdextensions/Project/build/dependencies/godot-cpp/build/release/gen/src/variant/utility_functions.cpp:732:74: error: 
enetheru commented 1 month ago

Context: gen/src/variant/utility_functions.cpp:708

Variant UtilityFunctions::min_internal(const Variant **p_args, GDExtensionInt p_arg_count) {
    static GDExtensionPtrUtilityFunction _gde_function = internal::gdextension_interface_variant_get_ptr_utility_function(StringName("min")._native_ptr(), 3896050336);
    CHECK_METHOD_BIND_RET(_gde_function, Variant());
    Variant ret;
    _gde_function(&ret, reinterpret_cast<GDExtensionConstVariantPtr *>(p_args), p_arg_count);
    return ret;
}

_gde_function is GDExtensionPtrUtilityFunction

gdextension_interface.h:212

typedef void (*GDExtensionPtrUtilityFunction)(GDExtensionTypePtr r_return, const GDExtensionConstTypePtr *p_args, int p_argument_count);

This int p_argument_count is an int. and p_arg_count is a GDExtensionInt aka int64_t

going into godotengine code https://github.com/search?q=repo%3Agodotengine%2Fgodot%20GDExtensionPtrUtilityFunction&type=code

There is nothing interesting in git blame on either godot/core/extension/gdextension_interface.h:212 or the definiton of typedef int64_t GDExtensionInt; on line 175 of the same file.

Appears to be a typo but I'm not really experienced with the details of how all this fits together, and I've been burned in the past thinking something is simple when it's not.

Since this is the C interface from the engine, I don't think you can correct it in gdextension.

There appears to be other int's in that header too.

dsnopek commented 1 month ago

Since this is the C interface from the engine, I don't think you can correct it in gdextension.

Yes, this would need to be changed in Godot first. And, unfortunately, for binary compatibility we can't just change GDExtensionPtrUtilityFunction, we'd need to add a new GDExtensionPtrUtilityFunction2 (with a 2 at the end) with the new signature.

This probably should be fixed in Godot, because ideally we'd be using GDExtensionInt for all integers, to avoid any compiler or platform-specific quirks.

However, as a workaround, I think we could change the way we generate code for utility_funcitons.hpp/cpp in godot-cpp to use int rather than GDExtensionInt?

enetheru commented 1 month ago

Is there any mechanism for adding breaking Changes into godot that wait for a major release cycle?

On Thu, Sep 26, 2024, 10:47 PM David Snopek @.***> wrote:

Since this is the C interface from the engine, I don't think you can correct it in gdextension.

Yes, this would need to be changed in Godot first. And, unfortunately, for binary compatibility we can't just change GDExtensionPtrUtilityFunction, we'd need to add a new GDExtensionPtrUtilityFunction2 (with a 2 at the end) with the new signature.

This probably should be fixed in Godot, because ideally we'd be using GDExtensionInt for all integers, to avoid any compiler or platform-specific quirks.

However, as a workaround, I think we could change the way we generate code for utility_funcitons.hpp/cpp in godot-cpp to use int rather than GDExtensionInt?

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot-cpp/issues/1080#issuecomment-2376949093, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANEDDWP6PCERYOZU4LGBKDZYQCOLAVCNFSM6AAAAABOXOBBVCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZWHE2DSMBZGM . You are receiving this because you commented.Message ID: @.***>

dsnopek commented 1 month ago

No, not yet. :-) We're all still recovering from the Godot 3 -> 4 transition, and so planning for how to handle the next major version release hasn't started. We're trying to include as much as we can into Godot 4 in a compatible way, which is definitely possible in this case, it'd just be a lot of effort for a very minor change.

In the short-term, I think updating the code generation to get rid of the compiler warning/error is probably the way to go.

dsnopek commented 1 month ago

Or, actually, another possibility is replacing the ints in gdextension_interface.h with int32_t? It's probably the same everywhere, and so we don't break compatibility - it'd be more of a "clarification" than a change. We'd still need to update the code generation in godot-cpp, though.