This is an archive of the discontinued LLVM Phabricator instance.

Drop 'dllimport' when redeclaring inline function template without the attribute (PR31695)
ClosedPublic

Authored by hans on Jan 25 2017, 3:25 PM.

Details

Summary

For non-template dllimport functions, MSVC allows providing an inline definition without spelling out the attribute again. In the example below, f remains a dllimport function.

__declspec(dllimport) int f();
inline int f() { return 42; }
int useit() {
  return f();
}

However, for a function template, not putting dllimport on the redeclaration causes it to be dropped. In the example below, f is not dllimport.

template <typename> __declspec(dllimport) int f();
template <typename> inline int f() { return 42; }

int useit() {
  return f<int>();
}

This patch makes Clang match MSVC for the second example.

MSVC does not warn about the attribute being dropped in the example above, but I think we should. (MSVC does warn if the inline keyword isn't used.)

Diff Detail

Repository
rL LLVM

Event Timeline

hans created this revision.Jan 25 2017, 3:25 PM
hans added a reviewer: rsmith.

+Richard in case you have any theories on why they do it like this.

rnk accepted this revision.Jan 30 2017, 8:56 AM

lgtm

This revision is now accepted and ready to land.Jan 30 2017, 8:56 AM
This revision was automatically updated to reflect the committed changes.