Bug 454757

Summary: strict-iterator false positive when calling a const member function through operator->
Product: [Developer tools] clazy Reporter: julien.cugniere
Component: generalAssignee: Unassigned bugs mailing-list <unassigned-bugs>
Status: REPORTED ---    
Severity: normal CC: julien.cugniere, smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description julien.cugniere 2022-06-02 16:59:19 UTC
SUMMARY

Clazy reports a spurious "Mixing iterators with const_iterators" when using iterator::operator-> to call a const member function. Using that same iterator to also call non-const member functions still produces the warning.

STEPS TO REPRODUCE
Apply clazy with "checks=strict-iterators" on the following file :
```
#include <QVector>
int main() {
	QVector<QString> v = { "hello" };
	QVector<QString>::iterator it = v.begin();
	if (!it->isEmpty()) {
		it->clear();
	}
}
````

OBSERVED RESULT
Clazy will report "Mixing iterators with const_iterators" on the "!it->isEmpty()" line.

EXPECTED RESULT
No warning should be produced.

SOFTWARE/OS VERSIONS
Qt Version: 5.15.2
Clazy: 1.11

ADDITIONAL INFORMATION
Using "!(*it).isEmpty()" instead of "!it->isEmpty()" removes the warning.