Bug 488995 - std::vector::operator[] and ::iterator:operator -> indexer problem with libc++
Summary: std::vector::operator[] and ::iterator:operator -> indexer problem with libc++
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-indexer (show other bugs)
Version: 9.0.0   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-04 03:21 EST by Michael Teske CLA
Modified: 2020-09-04 15:26 EDT (History)
2 users (show)

See Also:


Attachments
preprocessed cpp file (1.30 MB, application/octet-stream)
2016-03-08 03:02 EST, Michael Teske CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Teske CLA 2016-03-04 03:21:08 EST
I use El Capitan with XCode 7.2.1, eclipse cdt nightly build from yesterday.

Similar to bug #488456 there are problems with std::vector:

#include <vector>
#include <string>
int main() {
	std::vector<std::string> test(1);
	test[0].c_str(); // <----- error "c_str() could not be resolved"
        std::vector<std::string>::iterator x = test.begin();
        x->does_not_exist(); // <---- no error at all
        return 0;
}

content assist does not work on "x->" and test[0] as well.
Comment 1 Nathan Ridge CLA 2016-03-08 02:00:09 EST
Works for me on Linux, with libc++ headers (the same ones that allowed me to reproduce bug 488456), with the latest nightly.
Comment 2 Nathan Ridge CLA 2016-03-08 02:00:58 EST
Could you upload a preprocessed file, as described in bug 488456 comment 1? Thanks!
Comment 3 Michael Teske CLA 2016-03-08 03:02:46 EST
Created attachment 260146 [details]
preprocessed cpp file

The preprocessed file works.
Comment 4 Michael Teske CLA 2016-03-08 03:35:01 EST
Hmm it looks like rebuilding the index helps here, so I guess it's not 
an indexer bug. I should have tried this first but it looked so similar to 
the problem with the map.
 But:
It can be reproduced here any time by creating the default c++ "hello world" project, adding vector and string includes and putting 
	std::vector <std::string, std::string> v;
	v[0].c_str();
at the start of main. 
Only an indexer rebuild will remove the problems.
To which category should the bug be moved?
Comment 5 Nathan Ridge CLA 2016-03-08 03:50:34 EST
(In reply to Michael Teske from comment #4)
> Hmm it looks like rebuilding the index helps here

Ah, that explains why I couldn't reproduce it.

> It can be reproduced here any time by creating the default c++ "hello world"
> project, adding vector and string includes and putting 
> 	std::vector <std::string, std::string> v;
> 	v[0].c_str();
> at the start of main. 
> Only an indexer rebuild will remove the problems.

I still can't reproduce it like this, but that's probably because on my system, a newly created project uses libstdc++ headers by default, and I have to explicitly change it to use libc++, which triggers a re-index. I suspect that if the project used libc++ headers from the start, I could probably reproduce your problem.

> To which category should the bug be moved?

It's fine where it is. Errors that go away with a re-index are still indexer bugs, they're just hard to debug, and lower priority than errors that persist after a re-index.
Comment 6 Michael Teske CLA 2016-03-08 03:58:15 EST
fine. Let me know if I can do anything to help (e.g. trying test versions, provide some info, whatever). Anyway, you're right, priority is not that high anymore.
Comment 7 Nathan Ridge CLA 2016-03-08 04:05:41 EST
(In reply to Michael Teske from comment #6)
> Let me know if I can do anything to help (e.g. trying test versions,
> provide some info, whatever).

The next step would be to reduce the problematic code example across the libc++ headers, until it's self-contained, similar to bug 488456 comment 3. (The nature of this bug means that, unlike bug 488456 comment 3, the reduced example will still include at least one header file, but the contents of that header can be minimized.)

This is tricky to do, and time-consuming because - as the problem goes away with a reindex - you'd basically have to create a new project at each step of the reduction. I'd say it's probably not worth your time.