I recently came across the following function in the public SDK of an application that I work on:
virtual char* ExtentName() {return "";}
When I compile the application using Visual Studio with the /permissive-
flag, the function above causes the following compilation error:
error C2440: 'return': cannot convert from 'const char [1]' to 'char *'
note: Conversion from string literal loses const qualifier (see /Zc:strictStrings)
I'm really surprised this code compiles under any circumstances, because it's converting a string literal (in this case a null-terminator) into a char*
. How is that possible?
Additionally, I would like to fix this problem without causing an SDK break. This is what I consider the best solution:
virtual char* ExtentName() {return nullptr;}
The change above doesn't break the ABI, but I'm worried it could break our users' code, although I'm not sure how. Is that a possibility? Thank you for any information!