Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322711 - Error parsing map<...>::iterator as a type in the context of a template
Summary: Error parsing map<...>::iterator as a type in the context of a template
Status: RESOLVED INVALID
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 7.0   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-14 16:29 EDT by Bob Fraley CLA
Modified: 2011-01-07 07:51 EST (History)
4 users (show)

See Also:


Attachments
The template that fails (748 bytes, application/octet-stream)
2010-08-14 16:29 EDT, Bob Fraley CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Fraley CLA 2010-08-14 16:29:11 EDT
Created attachment 176606 [details]
The template that fails

I have a map defined within a template, using the template parameters.  The iterator is no longer properly recognized as a type.  It appears that the parser thinks that it shouldn't be a type, but it is, and the parser gets confused.  

The relevant message is:  
../main.c++:17: error: dependent-name 'std::map<Key,Val,std::less<_Key>,std::allocator<std::pair<const _Key, _Tp> > >::iterator' is parsed as a non-type, but instantiation yields a type

Note that it did not work making a separate type def for the iterator. 

I am attaching the failing program, and the same program that works fine when it is not a template.

Bob

PS:  Since I can't add 2 attachments, here is the good class.

#include <map>
#include <string>
#include <utility>
#include <iostream>
using namespace std;

class sym {
public:
	short find (string name) {
		map<string, short>::iterator res = tbl.find(name);
		if (res == tbl.end()) return undef_val;
		return res -> second;
	}
	void add (string name, short val) {tbl.insert(make_pair(name, val)); }
private:
	static short undef_val;
	map<string, short> tbl;
};

short sym::undef_val = 0;

int main(int argc, char * argv[]) {
   sym mytbl;
   string mystr = "abc";
   mytbl.add(mystr, 6);
   short i = mytbl.find(mystr);
   short j = mytbl.find("def");
   cout << "It ran: " << i << j << endl;
}
Comment 2 Markus Schorn CLA 2011-01-07 07:51:28 EST
The example code is wrong (see comment 1). In addtion to that, the error is generated by your compiler, not by CDT.