[cfe-dev] CodeCompletion for C++ Code in Buffers
fmclang
fmclang at mailinator.com
Sun Apr 5 03:30:12 PDT 2015
David Chisnall-4 wrote
> You can just specify a name ("
> <unsaved file>
> " or similar) and it will work fine.
Hi David,
thanks for your reply.
I already tried that with no success.
My test is a simple sequence of
clang_createIndex, clang_parseTranslationUnit and clang_codeCompleteAt.
-----------------------------------------------
const char* tmpCpp =
"struct MyStruct { void myFunc(int i); };\r\n"
"int main()\r\n"
"{\r\n"
" MyStruct s;\r\n"
" s.\r\n";
#define SRC_FILE "<unsaved_file>"
int main()
{
CXIndex idx = clang_createIndex(1, 0);
CXUnsavedFile* uf = new CXUnsavedFile[1];
uf[0].Filename = SRC_FILE;
uf[0].Contents = tmpCpp;
uf[0].Length = strlen(tmpCpp);
CXTranslationUnit u = clang_parseTranslationUnit(idx, SRC_FILE, nullptr,
0, uf, 1, 0);
CXCodeCompleteResults* res = clang_codeCompleteAt(u, SRC_FILE, 5, 6, uf,
1, clang_defaultCodeCompleteOptions());
}
-----------------------------------------------
If i define SRC_FILE to a real file of whatever content, everything works
fine.
But if the file does not exist, clang crashes in
clang_parseTranslationUnit_Impl()
at this line:
if (isASTReadError(Unit ? Unit.get() : ErrUnit.get())) <--------------
The problem is that both Unit and ErrUnit are nulltr and there is no
further check in isASTReadError() for nullptr. Is this a bug i did i make
something wrong?
Cheers
--
View this message in context: http://clang-developers.42468.n3.nabble.com/CodeCompletion-for-C-Code-in-Buffers-tp4044839p4044841.html
Sent from the Clang Developers mailing list archive at Nabble.com.
More information about the cfe-dev
mailing list