From c5dc759831291ef80d9e522b291e74d8ea05b712 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 17 Jun 2018 13:29:24 -0700 Subject: [PATCH] Put `static const` into IndexVar::def (a definition is not required unless odr-used) --- src/indexer.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index 229e671b..cdd7330f 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1495,13 +1495,17 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { var.def.kind = lsSymbolKind::Parameter; //} - if (decl->isDefinition) { + if (!decl->isDefinition) + var.declarations.push_back( + SetUse(db, spell, lex_parent, Role::Declaration)); + // For `static const`, a definition at namespace scope is not required + // unless odr-used. + if (decl->isDefinition || + (decl->entityInfo->kind == CXIdxEntity_CXXStaticVariable && + clang_isConstQualifiedType(clang_getCursorType(decl->cursor)))) { var.def.spell = SetUse(db, spell, sem_parent, Role::Definition); var.def.extent = SetUse(db, cursor.get_extent(), lex_parent, Role::None); - } else { - var.declarations.push_back( - SetUse(db, spell, lex_parent, Role::Declaration)); } cursor.VisitChildren(&AddDeclInitializerUsagesVisitor, db);