[PATCH] D29930: Add `__is_direct_constructible` trait for checking safe reference initialization.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 14 03:19:12 PST 2017


EricWF created this revision.

The STL types `std::pair` and `std::tuple` can both store reference types. However their constructors cannot adequately check if the initialization of reference types is safe.  For example:

  std::tuple<std::tuple<int> const&> t = 42;
  // The stored reference is already dangling.

This patch attempts to implement a traits that acts the same as `__is_constructible(type, argtypes...)` except when `type` is a reference. In which case the trait disallows initialization from a materialized temporary.  For example:

  static_assert(__is_constructible(int const&, long));
  static_assert(!__is_direct_constructible(int const&, long));

I don't think `__is_direct_constructible` is a good name, but I don't have any better ideas. All bikeshedding welcome.


https://reviews.llvm.org/D29930

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/TokenKinds.def
  include/clang/Basic/TypeTraits.h
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/type-traits.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29930.88341.patch
Type: text/x-patch
Size: 5135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170214/21a79b8f/attachment.bin>


More information about the cfe-commits mailing list