Skip to content

Fix compilation with -Wdouble-promotion #31

@jfirebaugh

Description

@jfirebaugh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions