Commit 9b3723d6 authored by Adam Strzelecki's avatar Adam Strzelecki Committed by Orgad Shaneh

CppTools: Do not highlight instantiation as call

Underlying C++ model sometimes marks C++ object instantiation using initializer
as a (forward) function declaration. This leads to incorrect highlighting of
object variables as if they were function calls.

C++ model however marks in this case (and not any other case) such symbols as
ambiguous function types, see CPlusPlus::Bind::visit. This change skips such
ambiguous functions for highlighting as function call.

Also add test case for related bug report.

Task-number: QTCREATORBUG-15212
Change-Id: Ifde8db407f2fa8275a3f991bfa3d3b73eca8c14e
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 87f6b92e
......@@ -1298,7 +1298,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST
Function *funTy = c->type()->asFunctionType();
if (!funTy) // Template function has an overridden type
funTy = r.type()->asFunctionType();
if (!funTy)
if (!funTy || funTy->isAmbiguous())
continue; // TODO: add diagnostic messages and color call-operators calls too?
if (argumentCount < funTy->minimumArgumentCount()) {
......
......@@ -1022,6 +1022,55 @@ void tst_CheckSymbols::test_checksymbols_data()
<< Use(3, 3, 7, Highlighting::LocalUse)
<< Use(3, 11, 10, Highlighting::FieldUse));
QTest::newRow("instantation_as_function_call_QTCREATORBUG15212")
<< _("struct Foo {};\n"
"template <typename Type> struct test {\n"
" test() {}\n"
" test(int, int) {}\n"
"};\n"
"void test(int int_argument) {\n"
" const int very_long_constant_of_type_int = 11111111111111111;\n"
" test<Foo> foo1;\n"
" test<Foo> foo2(int_argument, int_argument);\n"
" test<Foo> foo3(very_long_constant_of_type_int,\n"
" very_long_constant_of_type_int);\n"
" test<int> size1(int_argument, int_argument);\n"
" (void)foo1, foo2, foo3, size1;\n"
" test(int_argument);\n"
"}\n")
<< (UseList()
<< Use(1, 8, 3, Highlighting::TypeUse)
<< Use(2, 20, 4, Highlighting::TypeUse)
<< Use(2, 33, 4, Highlighting::TypeUse)
<< Use(3, 3, 4, Highlighting::TypeUse)
<< Use(4, 3, 4, Highlighting::TypeUse)
<< Use(6, 6, 4, Highlighting::FunctionUse)
<< Use(6, 15, 12, Highlighting::LocalUse)
<< Use(7, 13, 30, Highlighting::LocalUse)
<< Use(8, 3, 4, Highlighting::TypeUse)
<< Use(8, 8, 3, Highlighting::TypeUse)
<< Use(8, 13, 4, Highlighting::LocalUse)
<< Use(9, 3, 4, Highlighting::TypeUse)
<< Use(9, 8, 3, Highlighting::TypeUse)
<< Use(9, 13, 4, Highlighting::LocalUse)
<< Use(9, 18, 12, Highlighting::LocalUse)
<< Use(9, 32, 12, Highlighting::LocalUse)
<< Use(10, 3, 4, Highlighting::TypeUse)
<< Use(10, 8, 3, Highlighting::TypeUse)
<< Use(10, 13, 4, Highlighting::LocalUse)
<< Use(10, 18, 30, Highlighting::LocalUse)
<< Use(11, 18, 30, Highlighting::LocalUse)
<< Use(12, 3, 4, Highlighting::TypeUse)
<< Use(12, 13, 5, Highlighting::LocalUse)
<< Use(12, 19, 12, Highlighting::LocalUse)
<< Use(12, 33, 12, Highlighting::LocalUse)
<< Use(13, 9, 4, Highlighting::LocalUse)
<< Use(13, 15, 4, Highlighting::LocalUse)
<< Use(13, 21, 4, Highlighting::LocalUse)
<< Use(13, 27, 5, Highlighting::LocalUse)
<< Use(14, 3, 4, Highlighting::FunctionUse)
<< Use(14, 8, 12, Highlighting::LocalUse));
QTest::newRow("unicodeIdentifier1")
<< _("class My" TEST_UNICODE_IDENTIFIER "Type { int " TEST_UNICODE_IDENTIFIER "Member; };\n"
"void f(My" TEST_UNICODE_IDENTIFIER "Type var" TEST_UNICODE_IDENTIFIER ")\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment