<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59603>59603</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Linking failure with PCH built with -ffp-exception-behavior=maytrap
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          wthrowe
      </td>
    </tr>
</table>

<pre>
    Compiling this into a precompiled header will result in link failures on use if the PCH is compiled with `-ffp-exception-behavior=maytrap`, but not if the floating-point exception behavior is not changed or if no PCH is used.

`header.hpp`:
```c++
#pragma once
template<typename T>
struct S {
  template<typename = int>
  S();

 __attribute__((__always_inline__))
  void f() {}
};

void g() { S<int>{}; }

template<typename T>
template<typename>
S<T>::S() { f(); }

extern template class S<int>;
```
`main.cpp`:
```c++
#include "header.hpp"
int main() {
  return 0;
}
```
```
$ ./clang++ -std=c++17 -ffp-exception-behavior=maytrap main.cpp
# works
$ ./clang++ -std=c++17 -ffp-exception-behavior=maytrap header.hpp -o header.pch
$ ./clang++ -std=c++17 -ffp-exception-behavior=maytrap -include-pch header.pch main.cpp
/usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/main-2576ee.o: in function `S<int>::S<int>()':
main.cpp:(.text._ZN1SIiEC2IiEEv[_ZN1SIiEC2IiEEv]+0x11): undefined reference to `S<int>::f()'
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
```
The behavior does not depend on whether or not `-ffp-exception-behavior=maytrap` is passed to the final compilation.

The original case this was reduced from was
```c++
#include "std.hpp"
int main() {
 std::string{""};
  return 0;
}
```
with `std.hpp` just including `<string>` from libstdc++ 12, but I can't seem to get clang to pick up my gcc 12 install at the moment and it doesn't occur for gcc 11.

```
$ ./clang++ --version 
clang version 15.0.6
Target: x86_64-unknown-linux-gnu
Thread model: posix
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVlGL4z4O_zTui0hInDadPvSh0065heM4mH26l-LYSuIdxw6203a-_WEnTbszAzt_WDAttmTpJ0v6Kcw52WjELVk9k9VhwQbfGru9-NaaCy4qI963e9P1UkndgG-lA6m9AQa9RR4FKKBFJtDCRSoFFt2gPEgNSuo3qJlUg0UHRsPgEGQNvkX47_5fIB3MFi7St0DKLKnrPsErx95Lo5MKW3aWxpLi0LF3b1lPyozQPVSDB238zVytDPNSN0lvpPYwG4CbgeAs6POW6QYFhJMatLkBGRyKlGQHku2m3zIbo0rbPjot7oJxcUKfwxpPadFb1nQMjOY4nnnsesU8kmLv33vUrEP4SYqXUeq8HbiHVyDryQbAVzdIcQhPPt8DeCX0idANKZ4fAcPpxLy3sho8nk5R5el0YurC3t1JaiV1PN6ENRk6GymgHq1FGOvDZHF9-GA9qjZ3VXglxX6CNV4snuF-_xvxfyGdZcF41Cx2pNi9Prit59g_esOrR6vnJwSumHOPMOeAbgmctx2TOuXfTLPUXA0CgVD6UCCUjgqh-oK5h0edHtuiH6yG7I5jxv8J0G9buoSU0CNXTDcjFkicF6Q4TNDyNfyxbWCO8RYHXIx9c3_Vx_09IDG3Xc_bv-okmRKQ9Lx98PEpwOPgLKFHJStCjw3nhB6vT-WpXCY9T5TUwzVp9EDoMc_TIs0IPabp55-vr1QhwUclSLEDQo--6wk9BgAJXa1LxNQEidRQD5pHHiJl9liKY1nP-7Gm6XquvjmYYkfoU-rx6tPT__6Tv_6QL3v6Q768nMnq-dPJgdDn7JrnsUN2MGiBtdQowGKNFjVH8OYrLPUdQvQfc5Tkq2AFrQ0J2EU-Rxs4u2NaRGa_MTdepQduBEIOhD4Fok_OwZdDBKnPhrPwDDP3fKjxny3emVoYHLlaYI9ahMFxadG3aANrB8E350Tg9Z45hyIgiWNCaqamoRMB_Ub5AYWxshmVmMNx3l2YA4ti4CigtqYLB9_nCOfF9wgidkLIhfNW6iYIKA3rgYv_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