diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2015-06-20 22:37:53 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2015-06-29 09:22:08 +0000 |
commit | a77e32800c2bdfdccfcd6dfcacc48d3fa610daea (patch) | |
tree | 5bb11546c910ce312b660abc328cac3f364b69b7 /src/libs/3rdparty/cplusplus/Bind.cpp | |
parent | 70bc5e842c8ec11f17a8bcde4615eedb0a5cccaa (diff) |
C++: Ignore explicit template instantiations
Defined in section 14.7.2 of the standard.
Fixes completion for std::string.
The following explicit instantiation appears in bits/basic_string.tcc:
extern template class basic_string<char>;
This is wrongfully considered a specialization for a forward declaration
(like `template<> class basic_string<char>` is).
Introduce a new Symbol type for explicit instantiations.
Use-case:
template<class T>
struct Foo { T bar; };
template class Foo<int>;
void func()
{
Foo<int> foo;
foo.bar; // bar not highlighted
}
Change-Id: I9e35c8c32f6b78fc87b4f4f1fc903b42cfbd2c2b
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Diffstat (limited to 'src/libs/3rdparty/cplusplus/Bind.cpp')
-rw-r--r-- | src/libs/3rdparty/cplusplus/Bind.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/libs/3rdparty/cplusplus/Bind.cpp b/src/libs/3rdparty/cplusplus/Bind.cpp index c135de1673..0deb19dd54 100644 --- a/src/libs/3rdparty/cplusplus/Bind.cpp +++ b/src/libs/3rdparty/cplusplus/Bind.cpp @@ -2367,11 +2367,15 @@ bool Bind::visit(ParameterDeclarationAST *ast) bool Bind::visit(TemplateDeclarationAST *ast) { - Template *templ = control()->newTemplate(ast->firstToken(), 0); - templ->setStartOffset(tokenAt(ast->firstToken()).utf16charsBegin()); - templ->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd()); - ast->symbol = templ; - Scope *previousScope = switchScope(templ); + Scope *scope = 0; + if (ast->less_token) + scope = control()->newTemplate(ast->firstToken(), 0); + else + scope = control()->newExplicitInstantiation(ast->firstToken(), 0); + scope->setStartOffset(tokenAt(ast->firstToken()).utf16charsBegin()); + scope->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd()); + ast->symbol = scope; + Scope *previousScope = switchScope(scope); for (DeclarationListAST *it = ast->template_parameter_list; it; it = it->next) { this->declaration(it->value); @@ -2380,12 +2384,17 @@ bool Bind::visit(TemplateDeclarationAST *ast) this->declaration(ast->declaration); (void) switchScope(previousScope); - if (Symbol *decl = templ->declaration()) { - templ->setSourceLocation(decl->sourceLocation(), translationUnit()); - templ->setName(decl->name()); + Symbol *decl = 0; + if (Template *templ = scope->asTemplate()) + decl = templ->declaration(); + else if (ExplicitInstantiation *inst = scope->asExplicitInstantiation()) + decl = inst->declaration(); + if (decl) { + scope->setSourceLocation(decl->sourceLocation(), translationUnit()); + scope->setName(decl->name()); } - _scope->addMember(templ); + _scope->addMember(scope); return false; } |