This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/10291: error referencing a static local from a local struct in termplate code
- From: bangerth at dealii dot org
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, sebor at roguewave dot com
- Date: 2 Apr 2003 01:27:20 -0000
- Subject: Re: c++/10291: error referencing a static local from a local struct in termplate code
- Reply-to: bangerth at dealii dot org, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, sebor at roguewave dot com, gcc-gnats at gcc dot gnu dot org
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