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

Fix compilation with -Wdouble-promotion #31

Open
jfirebaugh opened this issue Apr 13, 2018 · 0 comments
Open

Fix compilation with -Wdouble-promotion #31

jfirebaugh opened this issue Apr 13, 2018 · 0 comments

Comments

@jfirebaugh
Copy link
Contributor

Currently if -Wdouble-promotion is enabled, then invoking methods that take float parameters will trigger the warning. For example:

    jni::Method<Tag, jni::jfloat> method = klass.GetMethod<void, jni::float>(...);
    object.Call(env, method, 0.0f);

The warning looks something like:

.../jni.hpp/include/jni/functions.hpp:202:73: error: implicit conversion increases floating-point precision: 'float' to 'double' [-Werror,-Wdouble-promotion]
           Wrap<jobject*>(env.NewObject(Unwrap(clazz), Unwrap(method), Unwrap(std::forward<Args>(args))...)));
                              ~~~~~~~~~                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../jni.hpp/include/jni/class.hpp:50:41: note: in instantiation of function template specialization 'jni::NewObject<signed char, signed char, short, short, int, int, long long, long long, float, double, unsigned char, jni::jstring *>' requested here
               return Object<TagType>(&NewObject(env, *clazz, method, Untag(args)...));

This is because float is automatically promoted to double in varargs.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48379 notes that this is a pretty useless case for this warning, but still, we could suppress it by introducing a templated Vararg function that does an explicit static cast in the case of float.

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

1 participant