c++/10291: error referencing a static local from a local struct in termplate code

sebor@roguewave.com sebor@roguewave.com
Wed Apr 2 01:06:00 GMT 2003


>Number:         10291
>Category:       c++
>Synopsis:       error referencing a static local from a local struct in termplate code
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 02 01:06:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     sebor@roguewave.com
>Release:        3.2
>Organization:
>Environment:

>Description:
The well-fomed program below fails to compile with gcc 3.2.

Regards
Martin
>How-To-Repeat:
$ cat t.cpp; gcc --version; gcc t.cpp
template <class T>
int foo ()
{
    static int i;

    struct S {
        int bar () {
            return i;
        }
    } s;

    return s.bar ();
}

int main ()
{
    foo<int>();
}

gcc (GCC) 3.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

t.cpp: In member function `int foo()::S::bar() [with T = int]':
t.cpp:12:   instantiated from `int foo() [with T = int]'
t.cpp:17:   instantiated from here
t.cpp:8: `i' undeclared (first use this function)
t.cpp:8: (Each undeclared identifier is reported only once for each function it 
   appears in.)
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list