Tim, c/c++ folks,
I have worked gcc47 patches in most of the major packages to the point where I have hit a common failure that I cannot solve. The common problem involves error: redeclaration of (foo). Usually involving some iterator. The list of packages that have a similar build failure are:
tde-kipi-plugins - error: redeclaration of 'TQListViewItemIterator it'
tde-tdepim - error: redeclaration of 'TQMap<TQGuardedPtr<KMFolder>, int>::Iterator it'
tde-k3b - error: redeclaration of 'K3bAudioEditorWidget::Range* r'
rosegarden - error: redeclaration of 'std::multiset<Rosegarden::Event*
I don't know what the various declarations are supposed to look like to begin with so I sure can't recognize which one, and in what scope, the declarations need to be fixed. Thanks for you help.
On 04/12/2012 04:07 PM, David C. Rankin wrote:
Tim, c/c++ folks,
I have worked gcc47 patches in most of the major packages to the point where I have hit a common failure that I cannot solve. The common problem involves error: redeclaration of (foo). Usually involving some iterator. The list of packages that have a similar build failure are:
tde-kipi-plugins - error: redeclaration of 'TQListViewItemIterator it'
tde-tdepim - error: redeclaration of 'TQMap<TQGuardedPtr<KMFolder>, int>::Iterator it'
tde-k3b - error: redeclaration of 'K3bAudioEditorWidget::Range* r'
rosegarden - error: redeclaration of 'std::multiset<Rosegarden::Event*
I don't know what the various declarations are supposed to look like to begin with so I sure can't recognize which one, and in what scope, the declarations need to be fixed. Thanks for you help.
Here is the code-block from rosegarden that is failing in src/document/RosegardenGUIDoc.cpp (line 2147 and 2152 designated with '*'):
* for (RecordingSegmentMap::iterator i = m_recordMIDISegments.begin(); i != m_recordMIDISegments.end(); ++i) {
Segment *s = i->second; * Segment::iterator i = s->begin();
if (i == s->end() || !(*i)->isa(Clef::EventType)) continue;
if ((*i)->getAbsoluteTime() < meaningfulBarStart) { Event *e = new Event(**i, meaningfulBarStart); s->erase(i); s->insert(e); }
I see the designations:
(1) RecordingSegmentMap::iterator i = m_recordMIDISegments.begin() (2) Segment::iterator i = s->begin();
How is the compiler seeing ' RecordingSegmentMap::' and 'Segment::' as the same thing?
More importantly, how to fix it?
This is all withing the scope of:
2087 void 2088 RosegardenGUIDoc::stopRecordingMidi() 2089 { ... 2229 }
Grepping it looks like it is declared a number of times:
archangel:/dat_e/tmp/rosegarden/src/document> grep -En 'Segment[A-Za-z]*::' RosegardenGUIDoc.cpp <snip> 2099: std::vectorRecordingSegmentMap::iterator toErase; 2101: for (RecordingSegmentMap::iterator i = m_recordMIDISegments.begin(); 2109: for (Segment::iterator i = s->begin(); i != s->end(); ++i) { 2147: for (RecordingSegmentMap::iterator i = m_recordMIDISegments.begin(); 2152: Segment::iterator i = s->begin(); 2592: (Segment::Audio); 2710: for (RecordingSegmentMap::iterator ri = m_recordAudioSegments.begin();
What to do?
On 04/12/2012 05:33 PM, David C. Rankin wrote: <snip>
archangel:/dat_e/tmp/rosegarden/src/document> grep -En 'Segment[A-Za-z]*::' RosegardenGUIDoc.cpp
<snip> 2099: std::vector<RecordingSegmentMap::iterator> toErase; 2101: for (RecordingSegmentMap::iterator i = m_recordMIDISegments.begin(); 2109: for (Segment::iterator i = s->begin(); i != s->end(); ++i) { 2147: for (RecordingSegmentMap::iterator i = m_recordMIDISegments.begin(); 2152: Segment::iterator i = s->begin(); 2592: (Segment::Audio); 2710: for (RecordingSegmentMap::iterator ri = m_recordAudioSegments.begin();
What to do?
Hmm.. This looks promising for rosegarden. At least a prior patch:
http://sourceforge.net/tracker/index.php?func=detail&aid=3475088&gro...
On 04/12/2012 05:57 PM, David C. Rankin wrote:
Hmm.. This looks promising for rosegarden. At least a prior patch:
http://sourceforge.net/tracker/index.php?func=detail&aid=3475088&gro...
Nevermind - our rosegarden is 6 years older than the patch. Back to patching...
On 12 Apr 2012, David C. Rankin told this:
Here is the code-block from rosegarden that is failing in src/document/RosegardenGUIDoc.cpp (line 2147 and 2152 designated with '*'):
for (RecordingSegmentMap::iterator i = m_recordMIDISegments.begin(); i != m_recordMIDISegments.end(); ++i) {
Segment *s = i->second;
Segment::iterator i = s->begin(); if (i == s->end() || !(*i)->isa(Clef::EventType)) continue; if ((*i)->getAbsoluteTime() < meaningfulBarStart) { Event *e = new Event(**i, meaningfulBarStart); s->erase(i); s->insert(e); }
I see the designations:
(1) RecordingSegmentMap::iterator i = m_recordMIDISegments.begin() (2) Segment::iterator i = s->begin();
How is the compiler seeing ' RecordingSegmentMap::' and 'Segment::' as the same thing?
It's not. The scope of variables declared in for loops was wrong in GCC 4.6 and below. (This is 'Detection of redeclared variables names in nested scopes' in the GCC 4.7 porting guide.)
The inside of the for loop's brackets and statement body are the same scope, not two scopes so redeclarating 'i' in both those places is an error.
The solution is to rename one of those variables. (It is generally easier to rename the outermost one, and its uses within the for loop's brackets and before the declaration of the *other* i.)