[cfe-dev] CodeCompletion for C++ Code in Buffers
Kevin Funk
kfunk at kde.org
Tue Apr 7 03:12:45 PDT 2015
On Sunday, April 05, 2015 03:30:12 AM fmclang wrote:
> 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?
Your code looks fine to me.
I've reported a bug report about this issue a while ago already:
https://llvm.org/bugs/show_bug.cgi?id=22282
We've seen the same issue in KDevelop.
>
>
> Cheers
>
>
>
>
>
>
> --
> View this message in context:
> http://clang-developers.42468.n3.nabble.com/CodeCompletion-for-C-Code-in-Bu
> ffers-tp4044839p4044841.html Sent from the Clang Developers mailing list
> archive at Nabble.com. _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
--
Kevin Funk | kfunk at kde.org | http://kfunk.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150407/661ea52d/attachment.sig>
More information about the cfe-dev
mailing list