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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Nikos Chantziaras-2
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).


_______________________________________________
help-gplusplus mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-gplusplus