Relates :
|
This is the Windows/Visual Studio companion to JDK-8223186 On 14/05/2019 10:21 am, Andrew Luo wrote: I've been trying to get the JDK to compile with the new /permissive- switch in VS2017 (https://devblogs.microsoft.com/cppblog/permissive-switch/) however there have been a few issues in various parts of the code. There are a few issues in the hotspot code where we attempt to assign string literals to char* (non-const) variables (unnecessarily). I took some time to fix some of these and attached a patch. Let me know if you have any comments/feedback. c:/Users/Andrew/Documents/mercurial/openjdk/jdk/test/hotspot/gtest/gtestMain.cpp(234): error C2440: 'initializing': cannot convert from 'const char [19]' to 'char *' c:/Users/Andrew/Documents/mercurial/openjdk/jdk/test/hotspot/gtest/gtestMain.cpp(234): note: Conversion from string literal loses const qualifier (see /Zc:strictStrings) c:/Users/Andrew/Documents/mercurial/openjdk/jdk/src/hotspot/os/windows/attachListener_windows.cpp(152): error C2664: 'AttachOperation::AttachOperation(AttachOperation &&)': cannot convert argument 1 from 'const char [9]' to 'char *' c:/Users/Andrew/Documents/mercurial/openjdk/jdk/src/hotspot/os/windows/attachListener_windows.cpp(152): note: Conversion from string literal loses const qualifier (see /Zc:strictStrings) c:/Users/Andrew/Documents/mercurial/openjdk/jdk/src/hotspot/os/windows/os_windows.cpp(204): error C2440: 'initializing': cannot convert from 'const char [5]' to 'char *' c:/Users/Andrew/Documents/mercurial/openjdk/jdk/src/hotspot/os/windows/os_windows.cpp(204): note: Conversion from string literal loses const qualifier (see /Zc:strictStrings) c:/Users/Andrew/Documents/mercurial/openjdk/jdk/src/hotspot/os/windows/os_windows.cpp(2214): error C2440: 'initializing': ... Patch: diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -201,7 +201,7 @@ char *home_path; char *dll_path; char *pslash; - char *bin = "\\bin"; + const char *bin = "\\bin"; char home_dir[MAX_PATH + 1]; char *alt_home_dir = ::getenv("_ALT_JAVA_HOME_DIR"); @@ -2185,7 +2185,7 @@ #define def_excpt(val) { #val, (val) } -static const struct { char* name; uint number; } exceptlabels[] = { +static const struct { const char* name; uint number; } exceptlabels[] = { def_excpt(EXCEPTION_ACCESS_VIOLATION), def_excpt(EXCEPTION_DATATYPE_MISALIGNMENT), def_excpt(EXCEPTION_BREAKPOINT), @@ -5335,7 +5335,7 @@ DWORD exit_code; char * cmd_string; - char * cmd_prefix = "cmd /C "; + const char * cmd_prefix = "cmd /C "; size_t len = strlen(cmd) + strlen(cmd_prefix) + 1; cmd_string = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtInternal); if (cmd_string == NULL) { @@ -5674,8 +5674,8 @@ */ int os::get_signal_number(const char* name) { static const struct { - char* name; - int number; + const char* name; + int number; } siglabels [] = // derived from version 6.0 VC98/include/signal.h {"ABRT", SIGABRT, // abnormal termination triggered by abort cl diff --git a/src/hotspot/share/services/attachListener.hpp b/src/hotspot/share/services/attachListener.hpp --- a/src/hotspot/share/services/attachListener.hpp +++ b/src/hotspot/share/services/attachListener.hpp @@ -121,7 +121,7 @@ const char* name() const { return _name; } // set the operation name - void set_name(char* name) { + void set_name(const char* name) { assert(strlen(name) <= name_length_max, "exceeds maximum name length"); size_t len = MIN2(strlen(name), (size_t)name_length_max); memcpy(_name, name, len); @@ -148,7 +148,7 @@ } // create an operation of a given name - AttachOperation(char* name) { + AttachOperation(const char* name) { set_name(name); for (int i=0; i<arg_count_max; i++) { set_arg(i, NULL); diff --git a/test/hotspot/gtest/gtestMain.cpp b/test/hotspot/gtest/gtestMain.cpp --- a/test/hotspot/gtest/gtestMain.cpp +++ b/test/hotspot/gtest/gtestMain.cpp @@ -231,7 +231,7 @@ #endif // __APPLE__ #else // _WIN32 - char* java_home_var = "_ALT_JAVA_HOME_DIR"; + const char* java_home_var = "_ALT_JAVA_HOME_DIR"; size_t len = strlen(java_home) + strlen(java_home_var) + 2; char * envString = new char[len]; sprintf_s(envString, len, "%s=%s", java_home_var, java_home);