diff options
author | Erich Keane <erich.keane@intel.com> | 2018-12-14 22:22:29 +0000 |
---|---|---|
committer | Erich Keane <erich.keane@intel.com> | 2018-12-14 22:22:29 +0000 |
commit | 46efdf2ccc2a80aefebf8433dbf9c7c959f6e629 (patch) | |
tree | 63ab727404da1afaca89c6578f37f135a50922e7 /lib/Sema/SemaInit.cpp | |
parent | 2a16197a4c0707d5e77c04ea46da663194b47a98 (diff) | |
download | clang-46efdf2ccc2a80aefebf8433dbf9c7c959f6e629.tar.gz |
Add extension to always default-initialize nullptr_t.
Core issue 1013 suggests that having an uninitialied std::nullptr_t be
UB is a bit foolish, since there is only a single valid value. This DR
reports that DR616 fixes it, which does so by making lvalue-to-rvalue
conversions from nullptr_t be equal to nullptr.
However, just implementing that results in warnings/etc in many places.
In order to fix all situations where nullptr_t would seem uninitialized,
this patch instead (as an otherwise transparent extension) default
initializes uninitialized VarDecls of nullptr_t.
Differential Revision: https://reviews.llvm.org/D53713
Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349201 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r-- | lib/Sema/SemaInit.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index c2f14229d8..57277f6e82 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -4881,6 +4881,13 @@ static void TryDefaultInitialization(Sema &S, return; } + // As an extension, and to fix Core issue 1013, zero initialize nullptr_t. + // Since there is only 1 valid value of nullptr_t, we can just use that. + if (DestType->isNullPtrType()) { + Sequence.AddZeroInitializationStep(Entity.getType()); + return; + } + // - otherwise, no initialization is performed. // If a program calls for the default initialization of an object of |