Candidate function not viable: no known conversion from 'LPTSTR' (aka 'char *') to 'const OLECHAR *' (aka 'const wchar_t *')

I’m not expecting a solution to change the source. Make Clang parse the Source without modifying.

TestClass.cpp

#include <Windows.h>

class TestClass {
public:
    TestClass(LPTSTR test);
};

TestClass::TestClass(LPTSTR i_dumpPath) {
    BSTR bstr = SysAllocString(i_dumpPath);
}

Command to run

clang TestClass.cpp -m32 -w

Output

TestClass.cpp:9:17: error: no matching function for call to 'SysAllocString'
    BSTR bstr = SysAllocString(i_dumpPath);
                ^~~~~~~~~~~~~~
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\oleauto.h:64:21: note: candidate function not viable: no known conversion from 'LPTSTR' (aka 'char *') to 'const OLECHAR *' (aka 'const wchar_t *') for
      1st argument
WINOLEAUTAPI_(BSTR) SysAllocString(__in_z_opt const OLECHAR * psz);
                    ^
1 error generated.

Verbose Output:

clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM-12\bin
 "C:\\Program Files\\LLVM-12\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.16.27042 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name TestClass.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -v -resource-dir "C:\\Program Files\\LLVM-12\\lib\\clang\\12.0.0" -internal-isystem "C:\\Program Files\\LLVM-12\\lib\\clang\\12.0.0\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\VC\\Tools\\MSVC\\14.16.27023\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\VC\\Tools\\MSVC\\14.16.27023\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\winrt" -fdeprecated-macro -fdebug-compilation-dir "C:\\Users\\Administrator\\Documents\\Veno\\CodeChecker" -ferror-limit 19 -fmessage-length=142 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.16.27042 -std=c++14 -fdelayed-template-parsing -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\TestClass-5ef61a.o" -x c++ TestClass.cpp
clang -cc1 version 12.0.0 based upon LLVM 12.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM-12\lib\clang\12.0.0\include
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\atlmfc\include
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt
 C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared
 C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um
 C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt
End of search list.
TestClass.cpp:9:17: error: no matching function for call to 'SysAllocString'
    BSTR bstr = SysAllocString(i_dumpPath);
                ^~~~~~~~~~~~~~
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\oleauto.h:74:21: note: candidate function not viable: no known conversion from
      'LPTSTR' (aka 'char *') to 'const OLECHAR *' (aka 'const wchar_t *') for 1st argument
WINOLEAUTAPI_(BSTR) SysAllocString(_In_opt_z_ const OLECHAR * psz);
                    ^
1 error generated.

OS : Windows 10
Clang Version : 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix

Tried to Compile C++ Source with Clang Compiler. But it results in an error relating to no matching call to function.

You’ll have to reset your expectations – the code doesn’t compile without modifying it. It doesn’t compile in MSVC either, for the same reason: see Compiler Explorer as an example.

SysAllocString requires an const OLECHAR * which is ultimately a const wchar_t * and you’re passing it a char * instead. My guess is that you wanted to define the _UNICODE macro so that LPTSTR is a wchar_t *.

Hi @AaronBallman… Thanks for your answer…
Adding Macro to the compiler argument with -DUNICODE solved the problem…