<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Clang accepts template specialization in C linkage"
   href="https://bugs.llvm.org/show_bug.cgi?id=46729">46729</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang accepts template specialization in C linkage
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>haoxintu@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi, all.

This code, test.cc, I am sure it's an invalid code but Clang compiles it well.

$cat test.cc
template <class> void F(){};
extern "C" { 
    template < >
    void F<int>(); 
}

While in other compilers I tested:

Output in GCC:
test.cc:3:5: error: template specialization with C linkage
    3 |     template < >
      |     ^~~~~~~~
test.cc:2:1: note: 'extern "C"' linkage started here
    2 | extern "C" {
      | ^~~~~~~~~~

Output in ICC:
test.cc(3): error: this declaration may not have extern "C" linkage
      template < >
      ^
Output in MSVC:
test.cc(3): error C2894: templates cannot be declared to have 'C' linkage

Interestingly, every Clang version from 5.0 onwards behaves the same, only
clang-4.0 rejects this.

Thanks,
Haoxin</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>