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
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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits