<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 - Linker error when function declared extern is defined statically in one TU and non-statically in second TU"
   href="https://bugs.llvm.org/show_bug.cgi?id=41073">41073</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Linker error when function declared extern is defined statically in one TU and non-statically in second TU
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>legalize@xmission.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21598" name="attach_21598" title="Reproducing case">attachment 21598</a> <a href="attachment.cgi?id=21598&action=edit" title="Reproducing case">[details]</a></span>
Reproducing case

See the attached code.  Reproduce with:

clang++ a.cpp b.cpp

Synopsis:

tmp.h declares extern void f();
a.cpp defines static void f() {}
b.cpp defines void f() {}

You get a linker error about multiply defined symbols.  However, this error
does not occur with gcc.  Gcc gives you an error (without -fpermissive) that
the function was declared extern and then defined static:

$ g++ a.cpp b.cpp
a.cpp: In function ‘void f()’:
a.cpp:2:15: error: ‘void f()’ was declared ‘extern’ and later ‘static’
[-fpermissive]
 static void f() {}
               ^
In file included from a.cpp:1:0:
tmp.h:1:13: note: previous declaration of ‘void f()’
 extern void f();
             ^

This is what I would expect from clang.  If I use -fpermissive with gcc, I
later get the multiply defined symbol error:

$ g++ -fpermissive a.cpp b.cpp
a.cpp: In function ‘void f()’:
a.cpp:2:15: warning: ‘void f()’ was declared ‘extern’ and later ‘static’
[-fpermissive]
 static void f() {}
               ^
In file included from a.cpp:1:0:
tmp.h:1:13: note: previous declaration of ‘void f()’
 extern void f();
             ^
/tmp/ccpDYwDv.o: In function `f()':
b.cpp:(.text+0x0): multiple definition of `f()'
/tmp/ccRPylP4.o:a.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status</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>