forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
Orgad Shaneh
parent
70bc5e842c
commit
a77e32800c
27
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
27
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user