https://bugs.llvm.org/show_bug.cgi?id=38029

            Bug ID: 38029
           Summary: Unused code triggers linker failure
           Product: clang
           Version: 6.0
          Hardware: Other
                OS: FreeBSD
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

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
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=229479

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to