help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Nikos Chantziaras
Subject: Code doesn't compile with GCC, but does with Clang and ICC
Date: Sat, 08 Dec 2012 03:14:00 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

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).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]