public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10291: error referencing a static local from a local struct in termplate code
@ 2003-04-02  1:27 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-04-02  1:27 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, sebor

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* c++/10291: error referencing a static local from a local struct in termplate code
@ 2003-04-02  1:06 sebor
  0 siblings, 0 replies; 2+ messages in thread
From: sebor @ 2003-04-02  1:06 UTC (permalink / raw)
  To: gcc-gnats


>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:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-04-02  1:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-02  1:27 c++/10291: error referencing a static local from a local struct in termplate code bangerth
  -- strict thread matches above, loose matches on Subject: below --
2003-04-02  1:06 sebor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).