[Bug c++/52688] New: static local variable can accessed from local class of function template
sir_nawaz959 at yahoo dot com
gcc-bugzilla@gcc.gnu.org
Fri Mar 23 17:20:00 GMT 2012
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'
More information about the Gcc-bugs
mailing list