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

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 17 20:58:16 PST 2017


sepavloff added a comment.

Is it correct to emit error in this case?

According to the Standard 10.5p1 "All function types, function names with external linkage, and variable names with external linkage have a language linkage". So templates do not have a language linkage.
The next paragraph, which introduces inkage-specification, states: "The string-literal indicates the required language linkage". So the construct `extern "C"`  specifies just language linkage, which is not pertinent to templates.

In 10.5p4 there is an example of a class defined in extern "C" construct:

  extern "C" {
    class X {
      void mf(); // the name of the function mf and the member function’s type have
                 // C++ language linkage
      void mf2(void(*)()); // the name of the function mf2 has C++ language linkage;
                           // the parameter has type “pointer to C function”
    };
  }

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.


https://reviews.llvm.org/D41179





More information about the cfe-commits mailing list