Webkit: Conversion from string literal loses const qualifier
Ali Ebrahimi
ali.ebrahimi1781 at gmail.com
Thu Apr 14 09:34:11 UTC 2016
Hi,
On Thu, Apr 14, 2016 at 11:30 AM, Murali Billa <murali.billa at oracle.com>
wrote:
> Hi Ali,
>
> Are you getting error due to 2nd OR 3rd parameter? As per your error,
> you are getting error for 3rd parameter right? As you already know, we
> fixed the issue for 3rd parameter.
>
> ..\..\..\..\src\main\native\Source\WebCore\platform\java\api\BackFo
> >>>> rwardListJava.cpp(46)
> >>>> : error C2664: 'jmethodID initMethod(JNIEnv *,jclass,char *,const
> >>>> char *)' : cannot convert argument 3 from 'const char [7]' to 'char *'
> >>>> Conversion from string literal loses const qualifier (see
> >>>> /Zc:strictStrings)
>
> I tried to reproduce the error for 2nd parameter with VS 2013 professional
> + update 5 on windows 7 64 bit. But Im not able to get the error for 2nd
> parameter and code is building successfully.
>
I build with VS2013 utimate update 5 on win 8.1 64 bit with WinSDK 8.1 and
get compile error. So I can not say anything here.
> Can you please confirm about which parameter(2nd/3rd) is causing the error
> for you?
>
I think indexing start from 1 in error msgs. argument 1, argument 2, ...
The error relates to parameter *name *in initMethod.
Please follow error msgs more precisely:
..\..\..\..\src\main\native\Source\WebCore\platform\java\api\BackForwardListJava
.cpp(46) : error C2664: 'jmethodID initMethod(JNIEnv *,jclass,char *,const
char*)' : cannot convert argument 3 from 'const char [7]' to 'char *'
Conversion from string literal loses const qualifier (see
/Zc:strictStrings)
Line 46:
* return initMethod(env, cls, "<init>", signature);*
Here, argument 3 is *"<init>"* (*const char [7]*) and its target type is *"char
*"* in initMethod signature. So here code implicitly tries to convert const
string to non-const string. If you want compiler not complain here you
should explicitly cast string literal to "char *".
return initMethod(env, cls, *(char*)*"<init>", signature);
..\..\..\..\src\main\native\Source\WebCore\platform\java\api\BackForwardListJava
.cpp(87) : error C2664: 'jmethodID initMethod(JNIEnv *,jclass,char *,const
char*)' : cannot convert argument 3 from *'const char [18]'* to 'char *'
Conversion from string literal loses const qualifier (see
/Zc:strictStrings)
Line 87:
static jmethodID notifyItemChangedMID = initMethod(env,
getJEntryClass(), "notifyItemChanged", "()V");
Here, argument 3 is *"notifyItemChanged" *with type *'const char [18]' *and
its target type is *"char *"* in initMethod signature.
Above error reason and workaround applies here.
static jmethodID notifyItemChangedMID = initMethod(env,
getJEntryClass(), (*char**)"notifyItemChanged", "()V");
..\..\..\..\src\main\native\Source\WebCore\platform\java\api\BackForwardListJava
.cpp(98) : error C2664: 'jmethodID initMethod(JNIEnv *,jclass,char *,const
char*)' : cannot convert argument 3 from *'const char [20]' *to 'char *'
Conversion from string literal loses const qualifier (see
/Zc:strictStrings)
Line 98:
initMethod(env, getJEntryClass(), "notifyItemDestroyed", "()V");
Here, argument 3 is "notifyItemDestroyed" with compiler type *'const char
[20]' *and target type is *"char *"* in initMethod signature.
Again all same.
workaound:
initMethod(env, getJEntryClass(), (*char**)"notifyItemDestroyed",
"()V");
..\..\..\..\src\main\native\Source\WebCore\platform\java\api\BackForwardListJava
.cpp(311) : error C2664: 'jmethodID initMethod(JNIEnv *,jclass,char *,const
char *)' : cannot convert argument 3 from 'const char [14]' to 'char *'
Conversion from string literal loses const qualifier (see
/Zc:strictStrings)
Line 311:
static jmethodID notifyChangedMID = initMethod(
env,
getJBFLClass(),
"notifyChanged",
"()V");
Finally, here argument 3 is "notifyChanged" with compiler type *'const char
[14]' *and target type is *"char *"* in initMethod signature.
So, same error and workaound:
static jmethodID notifyChangedMID = initMethod(
env,
getJBFLClass(),
(*char**)"notifyChanged",
"()V");
So we have two way,
1: add all above casts
2: change initMethod signature:
static jmethodID initMethod(JNIEnv* env, jclass cls, *const *char* name,
const char* signature)
Both works for me, but I vote for option 2.
What do you think?
--
Best Regards,
Ali Ebrahimi
More information about the openjfx-dev
mailing list