[PATCH] D29152: Drop 'dllimport' when redeclaring inline function template without the attribute (PR31695)

Hans Wennborg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 25 15:25:28 PST 2017


hans created this revision.

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.)


https://reviews.llvm.org/D29152

Files:
  lib/Sema/SemaDecl.cpp
  test/CodeGenCXX/dllimport.cpp
  test/SemaCXX/dllimport.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29152.85818.patch
Type: text/x-patch
Size: 19161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170125/c023aece/attachment-0001.bin>


More information about the cfe-commits mailing list