From 79b3e97abe194a4aa4b94581b1524797dc0a0927 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 7 Sep 2013 15:14:13 +0400 Subject: [PATCH 1/2] Fix 'vector subscription out of range' MSVC assertions --- cpp/ycm/ClangCompleter/TranslationUnit.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cpp/ycm/ClangCompleter/TranslationUnit.cpp b/cpp/ycm/ClangCompleter/TranslationUnit.cpp index c286c590..d3bc4a2a 100644 --- a/cpp/ycm/ClangCompleter/TranslationUnit.cpp +++ b/cpp/ycm/ClangCompleter/TranslationUnit.cpp @@ -56,13 +56,14 @@ TranslationUnit::TranslationUnit( std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles( unsaved_files ); + const UnsavedFile *unsaved = cxunsaved_files.size() > 0 ? &unsaved_files [0] : NULL; clang_translation_unit_ = clang_parseTranslationUnit( clang_index, filename.c_str(), &pointer_flags[ 0 ], pointer_flags.size(), - &cxunsaved_files[ 0 ], + (CXUnsavedFile *)unsaved, cxunsaved_files.size(), clang_defaultEditingTranslationUnitOptions() ); @@ -154,7 +155,7 @@ std::vector< CompletionData > TranslationUnit::CandidatesForLocation( std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles( unsaved_files ); - + const UnsavedFile *unsaved = cxunsaved_files.size() > 0 ? &unsaved_files [0] : NULL; // codeCompleteAt reparses the TU if the underlying source file has changed on // disk since the last time the TU was updated and there are no unsaved files. // If there are unsaved files, then codeCompleteAt will parse the in-memory @@ -170,7 +171,7 @@ std::vector< CompletionData > TranslationUnit::CandidatesForLocation( filename_.c_str(), line, column, - &cxunsaved_files[ 0 ], + (CXUnsavedFile *)unsaved, cxunsaved_files.size(), clang_defaultCodeCompleteOptions() ), clang_disposeCodeCompleteResults ); @@ -249,10 +250,10 @@ void TranslationUnit::Reparse( std::vector< CXUnsavedFile > &unsaved_files, if ( !clang_translation_unit_ ) return; - + CXUnsavedFile *unsaved = unsaved_files.size() > 0 ? &unsaved_files [0] : NULL; failure = clang_reparseTranslationUnit( clang_translation_unit_, unsaved_files.size(), - &unsaved_files[ 0 ], + unsaved, parse_options ); } From aadf5dd2b7db94a9efd2b09004f42af09404f958 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 7 Sep 2013 22:56:24 +0400 Subject: [PATCH 2/2] Fix class casting --- cpp/ycm/ClangCompleter/TranslationUnit.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cpp/ycm/ClangCompleter/TranslationUnit.cpp b/cpp/ycm/ClangCompleter/TranslationUnit.cpp index d3bc4a2a..0acc0681 100644 --- a/cpp/ycm/ClangCompleter/TranslationUnit.cpp +++ b/cpp/ycm/ClangCompleter/TranslationUnit.cpp @@ -56,14 +56,15 @@ TranslationUnit::TranslationUnit( std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles( unsaved_files ); - const UnsavedFile *unsaved = cxunsaved_files.size() > 0 ? &unsaved_files [0] : NULL; + const CXUnsavedFile *unsaved = cxunsaved_files.size() > 0 + ? &cxunsaved_files [0] : NULL; clang_translation_unit_ = clang_parseTranslationUnit( clang_index, filename.c_str(), &pointer_flags[ 0 ], pointer_flags.size(), - (CXUnsavedFile *)unsaved, + const_cast(unsaved), cxunsaved_files.size(), clang_defaultEditingTranslationUnitOptions() ); @@ -155,7 +156,8 @@ std::vector< CompletionData > TranslationUnit::CandidatesForLocation( std::vector< CXUnsavedFile > cxunsaved_files = ToCXUnsavedFiles( unsaved_files ); - const UnsavedFile *unsaved = cxunsaved_files.size() > 0 ? &unsaved_files [0] : NULL; + const CXUnsavedFile *unsaved = cxunsaved_files.size() > 0 + ? &cxunsaved_files [0] : NULL; // codeCompleteAt reparses the TU if the underlying source file has changed on // disk since the last time the TU was updated and there are no unsaved files. // If there are unsaved files, then codeCompleteAt will parse the in-memory @@ -171,7 +173,7 @@ std::vector< CompletionData > TranslationUnit::CandidatesForLocation( filename_.c_str(), line, column, - (CXUnsavedFile *)unsaved, + const_cast(unsaved), cxunsaved_files.size(), clang_defaultCodeCompleteOptions() ), clang_disposeCodeCompleteResults ); @@ -250,7 +252,8 @@ void TranslationUnit::Reparse( std::vector< CXUnsavedFile > &unsaved_files, if ( !clang_translation_unit_ ) return; - CXUnsavedFile *unsaved = unsaved_files.size() > 0 ? &unsaved_files [0] : NULL; + CXUnsavedFile *unsaved = unsaved_files.size() > 0 + ? &unsaved_files [0] : NULL; failure = clang_reparseTranslationUnit( clang_translation_unit_, unsaved_files.size(), unsaved,