Bug 299310 - Element type is incorrectly deduced in range-based for loop with QVector
Summary: Element type is incorrectly deduced in range-based for loop with QVector
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (old) (show other bugs)
Version: git master
Platform: openSUSE Linux
: NOR normal
Target Milestone: 4.3.0
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-03 17:02 UTC by Alexander Shaduri
Modified: 2012-05-14 19:25 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Shaduri 2012-05-03 17:02:54 UTC
I'm using KDevelop git master (2012-05-03).

Consider the following example:

#include <QVector>
void func()
{
	QVector<double> vec;
	for (auto elem : vec) {  // popup says elem is int
	}
}

The popup says "elem" variable is of type "int", when in fact it should be double&. Note that this problem occurs with QVector, QSet, etc..., but not with std::vector, std::list, etc...

Thanks

Reproducible: Always

Steps to Reproduce:
1. Try the code above.

Actual Results:  
Invalid type is deduced.

Expected Results:  
Correct type should be deduced.

openSUSE 12.1 x86-64, KDE 4.7.2.
Comment 1 Milian Wolff 2012-05-14 19:25:15 UTC
Git commit 25c9de709d85f6288ea2dcc68ee2ef15125015be by Milian Wolff.
Committed on 14/05/2012 at 21:16.
Pushed by mwolff into branch '4.3'.

Fix begin-lookup for auto-type deduction in range-based for loops.

First up, ensure we pick the proper list type by introducing a
virtual ContextBuilder::handleRangeBasedFor that is then overwritten
in the DeclarationBuilder. This way we can ensure that lastType()
actually returns the type we want.

Then, when we don't find a viable begin function in the current
namespace via ADL, fallback to ::std::begin (in accordance to the
spec) and repeat.

M  +7    -2    languages/cpp/cppduchain/contextbuilder.cpp
M  +1    -0    languages/cpp/cppduchain/contextbuilder.h
M  +39   -8    languages/cpp/cppduchain/declarationbuilder.cpp
M  +1    -1    languages/cpp/cppduchain/declarationbuilder.h
M  +0    -1    languages/cpp/cppduchain/overloadresolutionhelper.cpp
M  +1    -0    languages/cpp/cppduchain/tests/test_duchain.h
M  +62   -0    languages/cpp/cppduchain/tests/test_duchain_cpp2011.cpp

http://commits.kde.org/kdevelop/25c9de709d85f6288ea2dcc68ee2ef15125015be