[PATCH] D53713: Add extension to always default-initialize nullptr_t.
Erich Keane via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 25 09:45:16 PDT 2018
erichkeane created this revision.
erichkeane added reviewers: rsmith, aaron.ballman.
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.
Repository:
rC Clang
https://reviews.llvm.org/D53713
Files:
lib/Sema/SemaInit.cpp
test/SemaCXX/nullptr_t-init.cpp
Index: test/SemaCXX/nullptr_t-init.cpp
===================================================================
--- /dev/null
+++ test/SemaCXX/nullptr_t-init.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ffreestanding -Wuninitialized %s
+// expected-no-diagnostics
+typedef decltype(nullptr) nullptr_t;
+
+// Ensure no 'uninitialized when used here' warnings (Wuninitialized), for
+// nullptr_t always-initialized extension.
+nullptr_t default_init() {
+ nullptr_t a;
+ return a;
+}
Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4877,6 +4877,13 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53713.171123.patch
Type: text/x-patch
Size: 1102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181025/c8e70539/attachment-0001.bin>
More information about the cfe-commits
mailing list