| Summary: | Error parsing map<...>::iterator as a type in the context of a template | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Bob Fraley <fraleybob> | ||||
| Component: | cdt-parser | Assignee: | Project Inbox <cdt-parser-inbox> | ||||
| Status: | RESOLVED INVALID | QA Contact: | Markus Schorn <mschorn.eclipse> | ||||
| Severity: | major | ||||||
| Priority: | P3 | CC: | cdtdoug, iceberg.young, mknauer, yevshif | ||||
| Version: | 7.0 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | Macintosh | ||||||
| OS: | Mac OS X - Carbon (unsup.) | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
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; }