<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Functions marked as '__declspec(dllimport)' cannot be used as template arguments"
href="https://bugs.llvm.org/show_bug.cgi?id=38937">38937</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Functions marked as '__declspec(dllimport)' cannot be used as template arguments
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>duncan.horn@utexas.edu
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=20877" name="attach_20877" title="Simple repro">attachment 20877</a> <a href="attachment.cgi?id=20877&action=edit" title="Simple repro">[details]</a></span>
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>;
// ...</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>