diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2013-03-13 13:04:54 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-04-09 11:49:00 +0200 |
commit | 857457e057ac00f92a7d4f4152d8dd449094de1b (patch) | |
tree | 4d59ac1deb9ef83cb41d13140ca9fa1b86c2ba3f /src/libs/3rdparty/cplusplus | |
parent | 9d7e786b03b5af13048471a23d9f4ccb34b32d8e (diff) |
C++: handle non-arguments in function parameter scope gracefuly
Task-number: QTCREATORBUG-8316
Change-Id: I8897f75f30d3aeaf049cc792060c582ab1e3343d
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/libs/3rdparty/cplusplus')
-rw-r--r-- | src/libs/3rdparty/cplusplus/Symbols.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/libs/3rdparty/cplusplus/Symbols.cpp b/src/libs/3rdparty/cplusplus/Symbols.cpp index 9e9b66cacb8..6101e51485e 100644 --- a/src/libs/3rdparty/cplusplus/Symbols.cpp +++ b/src/libs/3rdparty/cplusplus/Symbols.cpp @@ -284,17 +284,32 @@ bool Function::hasReturnType() const unsigned Function::argumentCount() const { - unsigned c = memberCount(); - if (c > 0 && memberAt(0)->type()->isVoidType()) + const unsigned memCnt = memberCount(); + if (memCnt > 0 && memberAt(0)->type()->isVoidType()) return 0; - // Definitions with function-try-blocks will have more than a block. - while (c > 0 && memberAt(c - 1)->isBlock()) - --c; - return c; + + // Definitions with function-try-blocks will have more than a block, and + // arguments with a lambda as default argument will also have more blocks. + unsigned argc = 0; + for (unsigned it = 0; it < memCnt; ++it) + if (memberAt(it)->isArgument()) + ++argc; + return argc; } Symbol *Function::argumentAt(unsigned index) const -{ return memberAt(index); } +{ + for (unsigned it = 0, eit = memberCount(); it < eit; ++it) { + if (Argument *arg = memberAt(it)->asArgument()) { + if (index == 0) + return arg; + else + --index; + } + } + + return 0; +} bool Function::hasArguments() const { @@ -381,7 +396,7 @@ bool Function::maybeValidPrototype(unsigned actualArgumentCount) const for (; minNumberArguments < argc; ++minNumberArguments) { Argument *arg = argumentAt(minNumberArguments)->asArgument(); - if (! arg) // TODO: Fix me properly - QTCREATORBUG-8316 + if (! arg) return false; if (arg->hasInitializer()) |