[clang] [clang] Fix loss of `dllexport` for exported template specialization (PR #93302)

via cfe-commits cfe-commits at lists.llvm.org
Wed May 29 05:52:53 PDT 2024


zmodem wrote:

> I understand that removing the code that drops `dllexport` may not be the "best" place to fix this issue but if this code is not actually required, which appears to be the case (please let me know if this is not), then removing the code to achieve "better" behaviour feels like a "win". The alternative would be to add more code/complexity to the AST handling.

I still think fixing the AST would be better. That would also fix the "dllimport version" of your test case:

```
struct s {
  template <bool b = true> static bool f();
};
template <typename T> bool template_using_f(T) { return s::f(); }
bool use_template_using_f() { return template_using_f(0); }

template<> inline
bool __declspec(dllimport) s::f<true>() { return true; }
```

Here, `dllimport` gets dropped from `s::f<true>()` for the same reason as in your test: the AST node which the call in `template_using_f()` refers to is missing the attribute. (Godbolt: https://godbolt.org/z/nnfET4r13)

https://github.com/llvm/llvm-project/pull/93302


More information about the cfe-commits mailing list