[llvm-bugs] [Bug 38937] New: Functions marked as '__declspec(dllimport)' cannot be used as template arguments

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 13 10:26:41 PDT 2018


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

            Bug ID: 38937
           Summary: Functions marked as '__declspec(dllimport)' cannot be
                    used as template arguments
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: duncan.horn at utexas.edu
                CC: llvm-bugs at lists.llvm.org

Created attachment 20877
  --> https://bugs.llvm.org/attachment.cgi?id=20877&action=edit
Simple repro

I've attached a simple cpp file that repros this. To compile run "clang-cl
/std:c++17 main.cpp". The jist of the issue is that something like:

some_type<::CloseHandle> x;

will fail to compile with:

error: non-type template argument is not a constant expression

Because 'CloseHandle' is a function marked as '__declspec(dllimport)'. There is
a relatively simple workaround:

BOOL MyCloseHandle(HANDLE handle) { return ::CloseHandle(handle); }
some_type<MyCloseHandle> x;

However that can be tedious. More "production" use may look more like:

using unique_handle = unique_resource<HANDLE, ::CloseHandle,
invalid_handle_traits>;
using unique_hfind = unique_resource<HANDLE, ::FindClose,
invalid_handle_traits>;
using unique_heap = unique_resource<HANDLE, ::HeapDestroy, null_handle_traits>;
// ...

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180913/bfdfa83f/attachment.html>


More information about the llvm-bugs mailing list