This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Synopsis: error referencing a static local from a local struct in termplate code

State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Wed Apr  2 01:27:20 2003
State-Changed-Why:
    Confirmed with 2.95, 3.2, 3.3. With 3.4, it compiles,
    but doesn't link (see below).
    
    This testcase actually has rather interesting questions
    to offer for people who like thinking about the implications
    of two-stage name lookup, such as
    - 'i' being a variable in a template dependent namespace,
      it shouldn't be seen during first phase parsing
    - one would then need to qualify it
    - but how do you qualify function-local objects?
    
    For 3.4: as said, it compiles but doesn't link:
    g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ x.cc
    /tmp/cceV3jl1.o: In function `int foo<int>()::S::bar()':
    /tmp/cceV3jl1.o(.text+0x1c): undefined reference to `i'
    collect2: ld returned 1 exit status
    
    Something is not quite right here -- take this small
    modification (introduce another -- global -- variable 'i',
    give initializers to variables, and generate a return value):
    --------------------------
    int i = 0;
    
    template <class T>
    int foo ()
    {
        static int i = 1;
    
        struct S {
            int bar () {
                return i;
            }
        } s;
    
        return s.bar ();
    }
    
    int main ()
    {
        return foo<int>();
    }
    ------------------------------
    
    This links, but surprisingly returns zero! 
       g/x> ./a.out ; echo $?
       0
    Weird...
    W.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10291


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]