[PATCH] D41179: [Sema] Diagnose template specializations with C linkage

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 27 10:51:48 PST 2017


sepavloff added a comment.

In https://reviews.llvm.org/D41179#964526, @faisalv wrote:

> In https://reviews.llvm.org/D41179#964522, @miyuki wrote:
>
> > In https://reviews.llvm.org/D41179#957992, @sepavloff wrote:
> >
> > >   Classes do not have language linkage according to 10.5p1, just as templates, so this code is valid.
> > >  
> > >   It looks like defining templates inside extern "C" blocks is OK.
> >
> >
> > Currently both Clang and GCC diagnose class templates declared inside an 'extern "C"' block. I'm not sure how to proceed about this.
>
>
> Given that Clause 17 p6 specifically uses 'shall' to call out templates - i believe the implementation is expected to diagnose this.  10.5p1 (or is there another mention in the standard?) does not explicitly call out 'classes' as not having c language linkage - so implementations can get away not diagnosing this - and perhaps even allow classes to have language linkage on certain implementations?? (at least that's my squinty interpretation)


This is a strange clause. The language linkage describes cases when an entity defined in one TU is identical to another entity in another TU implemented in different language. As templates have no meaning outside C++, so they merely cannot have C linkage.

I guess the statement about C linkage in 17p6 is a remnant of those times when template were allowed to have `export` specifier. In that case templates would have external representation and in principle could be used in non C++ compilation.

Maybe @rsmith could clarify this point?


https://reviews.llvm.org/D41179





More information about the cfe-commits mailing list