trinity-devel@lists.pearsoncomputing.net

Message: previous - next
Month: April 2012

Re: [trinity-devel] coders - need help with gcc47 - redeclaration of (x) issue in several packages

From: Nix <nix@...>
Date: Fri, 13 Apr 2012 22:21:41 +0100
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.)

-- 
NULL && (void)