Skip to content

Commit 04e705d

Browse files
committed
SWBCSupport: silence C++17 deprecation warnings
The `std::codecvt` methods here have been deprecated in C++17. Adopt the use of `MultibyteToWideString` to remove the warnings about deprecation.
1 parent 095b2d1 commit 04e705d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/SWBCSupport/CLibclang.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,14 +1305,22 @@ struct LibclangWrapper {
13051305
LibclangWrapper(std::string path)
13061306
: path(path),
13071307
#ifdef _WIN32
1308-
handle(LoadLibraryW(std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(path).c_str())),
1308+
handle(nullptr),
13091309
#elif defined(__APPLE__)
13101310
// Use RTLD_LOCAL/RTLD_FIRST because we may load more than one copy of libclang, and we don't want to mix and match symbols from more than one library in one wrapper instance.
13111311
handle(dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL | RTLD_FIRST)),
13121312
#else
13131313
handle(dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL)),
13141314
#endif
13151315
isLeaked(false), hasRequiredAPI(true), hasDependencyScanner(true), hasStructuredScanningDiagnostics(true), hasCAS(true) {
1316+
#if defined(_WIN32)
1317+
DWORD cchLength = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path.c_str(), -1, nullptr, 0);
1318+
std::unique_ptr<wchar_t[]> wszPath(new wchar_t[cchLength]);
1319+
if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path.c_str(), -1, wszPath.get(), cchLength))
1320+
return;
1321+
handle = LoadLibraryW(wszPath.get());
1322+
#endif
1323+
13161324
if (!handle) return;
13171325

13181326
#define LOOKUP(name) ({ \

0 commit comments

Comments
 (0)