Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 369656 - auto type variable of type reverse_iterator is not correctly resolved
Summary: auto type variable of type reverse_iterator is not correctly resolved
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-indexer (show other bugs)
Version: 8.1.0   Edit
Hardware: PC Linux
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on: 327300
Blocks:
  Show dependency tree
 
Reported: 2012-01-25 08:24 EST by Gunther Piez CLA
Modified: 2016-12-29 18:28 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gunther Piez CLA 2012-01-25 08:24:52 EST
Build Identifier: 8.1.0.201201231635

I have the code

    std::multimap<float, std::string> sortedList;
    for (auto i=sortedList.rbegin(); i!=sortedList.rend(); ++i)
        std::cout << std::setw(40) << std::left << i->second << i->first << std::endl;

I get "second", "first" and "std::cout" marked as errors and the marker reads "Field second could not be resolved - Invalid overload of std::cout - Field first could not be resolved".

If I replace the second line with

    for (std::multimap<float, std::string>::iterator i=sortedList.rbegin(); i!=sortedList.rend(); ++i)

which is wrong and does not compile, the error markers are gone, if I use

    for (std::multimap<float, std::string>::reverse_iterator i=sortedList.rbegin(); i!=sortedList.rend(); ++i)

which is the correct type, it gets marked as an error.

Reproducible: Always

Steps to Reproduce:
Use auto variable of a reverse_iterator type.
Comment 1 Gunther Piez CLA 2012-01-25 08:26:38 EST
The bug title is misleading, while typing I discovered that not the usage of auto seems to be the culprit, but rather the reverse_iterator.
Comment 2 Markus Schorn CLA 2012-01-27 07:22:39 EST
I cannot reproduce the problem, most likely it depends on the system headers in use. What's the version of the compiler you are using?
Comment 3 Gunther Piez CLA 2012-01-27 11:36:31 EST
gcc 4.6.2

If I hover over the "i" variable in the not working case, I get a tooltip with line 129-133 from the file stl_iterator.h, where the copy constructor of a reverse_iterator is defined.

      /**
       *  The copy constructor is normal.
      */
      reverse_iterator(const reverse_iterator& __x)
      : current(__x.current) { }

So it seems the return type of rbegin() is correctly recognized.
Comment 4 Gunther Piez CLA 2012-03-30 19:10:20 EDT
The reason for the wrong parsing is possibly the noexcept keyword. Eclipse doesn't seem to recognize it, and it's freely used in newer versions of the gcc stdlibc++ . Similar issues arise with constexpr, but for the latter it can easily replaced with a macro which expands to nothing.

This makes the gcc std c++ library basically unusable in C++11 mode.
Comment 5 Nathan Ridge CLA 2012-05-08 04:17:15 EDT
(In reply to comment #3)
> gcc 4.6.2

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=374993#c4 for workaround.
Comment 6 Nathan Ridge CLA 2014-04-28 02:18:14 EDT
The code in question is parsed correctly with CDT 8.3 (I tried GCC 4.6 and GCC 4.9 headers). I think we can close this report.
Comment 7 Nathan Ridge CLA 2016-12-29 18:28:53 EST
Closing per comment 6.