<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 - Unused code triggers linker failure"
   href="https://bugs.llvm.org/show_bug.cgi?id=38029">38029</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unused code triggers linker failure
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>FreeBSD
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>adridg@FreeBSD.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This program fails to link (clang6 on FreeBSD):

```
#include <string> 
static std::string f() { return std::string(); } 
int main() { (void) f; }
```

The error message is

```
/tmp/t-a76eba.o: In function `f()':
t.cpp:(.text+0x20): undefined reference to `std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string()'
/usr/bin/ld: a.out: hidden symbol
`_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC2Ev' isn't
defined
/usr/bin/ld: final link failed: Nonrepresentable section on output
```

It also fails with clang5 on FreeBSD, on FreeBSDs 11- and 12-, and reportedly
on Linux with clang6 and -stdlib=libc++.

It doesn't fail with -O1 or above. It doesn't fail if you remove the `(void)f;`
statement, although then you will get an unused function warning.

Also reported downstream as
<a href="https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229479">https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229479</a></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>