[cfe-dev] [llvm-commits] [llvm] r158787 - in /llvm/trunk:

Ahmed Charles ahmedcharles at gmail.com
Wed Jun 27 14:53:07 PDT 2012


 include/llvm/Analysis/LoopInfo.h include/llvm/Analysis/LoopInfoImpl.h

 lib/Analysis/LoopInfo.cpp lib/CodeGen/MachineLoopInfo.cpp
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

MSVC's extern template feature is mostly the same as what is
standardized. However, it was implemented before it was considered for
standardization and VC11 is the first version that implements the
standardized behavior.

The big difference is that you don't need the ifdef around the extern
in header, because the standard allows you to have:

extern template Holder<int>;

template Holder<int>;

Versions of MSVC before 11 require that you not have the extern before
the explicit instantiation.
From: Kim Gr=C3=A4sman
Sent: 6/26/2012 11:46 AM
To: Nico Weber
Cc: Clang
Subject: Re: [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
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=C3=A4sman <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

_______________________________________________
cfe-dev mailing list
cfe-dev at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list