Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Code doesn't compile with GCC, but does with Clang and ICC

9 views
Skip to first unread message

Nikos Chantziaras

unread,
Dec 7, 2012, 8:14:00 PM12/7/12
to help-gp...@gnu.org
Why doesn't the below code compile with GCC?

#include <iostream>

template <typename T>
static void fFunc()
{
static T var;
(void)var; // Suppress set-but-not-used warning.
struct g {
static void gFunc()
{
std::cin >> var;
};
};
g::gFunc();
}

int main()
{
fFunc<int>();
}

It fails at link time with:

/tmp/ccYDfCzj.o: In function `gFunc':
tst.cpp:11: undefined reference to `var'

I'm using GCC 4.7.2 on Gentoo Linux (x86-64). It compiles fine with
Clang (3.1) and ICC (13.0.0).


0 new messages