diff --git a/src/clang_complete.cc b/src/clang_complete.cc index b3466ad4..3e52839f 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -470,6 +470,9 @@ void *DiagnosticMain(void *manager_) { BuildCompilerInvocation(session->file.args, FS); if (!CI) continue; + // If main file is a header, add -Wno-unused-function + if (lookupExtension(session->file.filename).second) + CI->getDiagnosticOpts().Warnings.push_back("no-unused-function"); CI->getDiagnosticOpts().IgnoreWarnings = false; CI->getLangOpts()->SpellChecking = g_config->diagnostics.spellChecking; StoreDiags DC(path); diff --git a/src/indexer.cc b/src/indexer.cc index 3a7aecf3..bc10732f 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -513,11 +513,12 @@ public: // e.g. operator type-parameter-1 i = 0; def.short_name_offset = 0; - } else if (short_name.size() && (!i || name[i - 1] != ':')) { + } else if (short_name.empty() || (i >= 2 && name[i - 2] == ':')) { + // Don't replace name with qualified name in ns::name Cls::*name + def.short_name_offset = i; + } else { name.replace(i, short_name.size(), qualified); def.short_name_offset = i + qualified.size() - short_name.size(); - } else { - def.short_name_offset = i; } def.short_name_size = short_name.size(); for (int paren = 0; i; i--) { @@ -538,7 +539,7 @@ public: std::string_view qualified, IndexVar::Def &def) { QualType T; const Expr *init = nullptr; - bool binding = false; + bool deduced = false; if (auto *VD = dyn_cast(D)) { T = VD->getType(); init = VD->getAnyInitializer(); @@ -548,9 +549,21 @@ public: init = FD->getInClassInitializer(); } else if (auto *BD = dyn_cast(D)) { T = BD->getType(); - binding = true; + deduced = true; } - if (!T.isNull() && (binding || T->getContainedDeducedType())) { + if (!T.isNull()) { + if (T->getContainedDeducedType()) { + deduced = true; + } else if (auto *DT = dyn_cast(T)) { + // decltype(y) x; + while (DT && !DT->getUnderlyingType().isNull()) { + T = DT->getUnderlyingType(); + DT = dyn_cast(T); + } + deduced = true; + } + } + if (!T.isNull() && deduced) { SmallString<256> Str; llvm::raw_svector_ostream OS(Str); PrintingPolicy PP = GetDefaultPolicy(); @@ -657,7 +670,11 @@ public: public: IndexDataConsumer(IndexParam ¶m) : param(param) {} - void initialize(ASTContext &Ctx) override { this->Ctx = param.Ctx = &Ctx; } + void initialize(ASTContext &Ctx) override { + this->Ctx = param.Ctx = &Ctx; + SourceManager &SM = Ctx.getSourceManager(); + (void)param.ConsumeFile(*SM.getFileEntryForID(SM.getMainFileID())); + } bool handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles, ArrayRef Relations, #if LLVM_VERSION_MAJOR >= 7