[PATCH] D43320: Allow dllimport non-type template arguments in C++17

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 14 14:55:04 PST 2018


rnk created this revision.
rnk added a reviewer: rsmith.

When the C++ committee changed the wording around non-type template
arguments, they naively thought that every global declarations address
would be a constant expression, but this is not the case.  There is no
PE/COFF relocation that allows using the address of a dllimport global
in another global. Therefore, we do not consider them constexpr, because
users expect that constexpr globals do not require dynamic
initialization.

However, there's nothing that prevents us from doing template
instantiation with dllimported non-type template parameters, so we
should allow it. That's what this patch does.

Fixes PR35772.

At first I tried to implement this as another evaluation mode
'EM_NonTypeTemplateArgument', but I would need rvalue and lvalue
varaints in order to preserve existing behavior around side effects.


https://reviews.llvm.org/D43320

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/dllimport-constexpr.cpp
  clang/test/SemaCXX/dllimport-memptr.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43320.134324.patch
Type: text/x-patch
Size: 7740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180214/5840415f/attachment-0001.bin>


More information about the cfe-commits mailing list