We’re updating a project to c++20, and are running into errors where we pass string literals into functions which take char *. I know this has been changed to make code more safe, but we are interfacing with libraries which we cannot change.
I’d rather not disable the strict treatment of literals via compiler flags, so is there a good way to wrap these literals just in these particular cases?
I was thinking of an inline function, that was named something specific to the library, that internally would use const_cast. That way later if we want to change the code because the library gets updated, we know exactly where to look.
Any other ideas?
constsince C++98 and before./permissive-)? In that case/std:c++20also now implies the conformance mode, resulting in the appropriate error. Or have you been using a pre-C++11 standard and ignored the deprecation warnings? I think it would benefit your question if you clarified that.constpointer is, but that has been true even when the implicit cast tochar*was still possible and I don't think any compiler made stronger guarantees. So replacing the implicit casts with explicit ones will not affect whether the code has UB. I am assuming that the library simply doesn't specifyconstwhere it expects aconstargument, in which case such a wrapper is fine. This may be a third-party library that they cannot modify.