[cfe-dev] [llvm-commits] [llvm] r158787 - in /llvm/trunk: include/llvm/Analysis/LoopInfo.h include/llvm/Analysis/LoopInfoImpl.h lib/Analysis/LoopInfo.cpp lib/CodeGen/MachineLoopInfo.cpp

Kim Gräsman kim.grasman at gmail.com
Tue Jun 26 11:42:54 PDT 2012


Hi Nico,

On Wed, Jun 20, 2012 at 5:14 PM, Nico Weber <thakis at chromium.org> wrote:
> On Wed, Jun 20, 2012 at 4:37 AM, Kim Gräsman <kim.grasman at gmail.com> wrote:
>
>> I'm almost sure MSVC is fine with extern template; I didn't know the
>> language feature existed until about a year ago, and my experiments
>> seemed to indicate it worked fine in VC 10.
>
> It doesn't work in MSVC2008.

(let me know if this is of no interest to the Clang list, and I'll
stop responding)

I found my scratch project and it turned out to be MSVC2008. I'm not
sure if I'm proving the existence of the same feature, but here's what
I've tried:

--
// holder.h
template< class T >
struct Holder
{
  Holder(const T& t)
    : value(t)
  {
  }

  T value;
};

#ifndef MY_HOLDER_SPECIALIZATIONS
extern template Holder<int>;
extern template Holder<std::string>;
extern template Holder<float>;
#endif

// holder_specializations.cc
#define MY_HOLDER_SPECIALIZATIONS
#include "holder.h"

template Holder<int>;
template Holder<std::string>;
template Holder<float>;

// main.cc
#include <iostream>
#include "holder.h"

int main()
{
  Holder<int> i(100);
  Holder<std::string> s("bob");
  Holder<float> f(3.14f);

  std::cout << i.value << std::endl;
  std::cout << s.value << std::endl;
  std::cout << f.value << std::endl;

  return 0;
}
--

This compiles and yields;

holder.h(15) : warning C4231: nonstandard extension used : 'extern'
before template explicit instantiation

I haven't tried to dig into whether this does the right thing (i.e.
suppress generation of duplicate symbols), so maybe that's where it's
failing?

Is this different from what you expected?

- Kim




More information about the cfe-dev mailing list