This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52688] New: static local variable can accessed from local class of function template
- From: "sir_nawaz959 at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 23 Mar 2012 16:56:20 +0000
- Subject: [Bug c++/52688] New: static local variable can accessed from local class of function template
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52688
Bug #: 52688
Summary: static local variable can accessed from local class of
function template
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: sir_nawaz959@yahoo.com
As per the C++ specification, static local variable can be accessed from local
class of function template, but GCC 4.6.1 gives error for the following
code-snippet:
template<typename T>
T f()
{
static const double staticLocalVariable = 100.0;
struct local
{
static double f() { return staticLocalVariable; }
};
return T(local::f());
}
int main() {
std::cout << f<double>() << std::endl;
}
While gcc-4.5.1 compiles fine this code, gcc-4.6.1 gives error, saying:
undefined reference to `staticLocalVariable'