summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2018-12-14 22:22:29 +0000
committerErich Keane <erich.keane@intel.com>2018-12-14 22:22:29 +0000
commit46efdf2ccc2a80aefebf8433dbf9c7c959f6e629 (patch)
tree63ab727404da1afaca89c6578f37f135a50922e7 /test
parent2a16197a4c0707d5e77c04ea46da663194b47a98 (diff)
downloadclang-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 'test')
-rw-r--r--test/Analysis/nullptr.cpp17
-rw-r--r--test/SemaCXX/ast-print-crash.cpp2
-rw-r--r--test/SemaCXX/nullptr_t-init.cpp10
3 files changed, 17 insertions, 12 deletions
diff --git a/test/Analysis/nullptr.cpp b/test/Analysis/nullptr.cpp
index 38e099b7fb..1d913c11d3 100644
--- a/test/Analysis/nullptr.cpp
+++ b/test/Analysis/nullptr.cpp
@@ -125,21 +125,16 @@ struct Type {
};
void shouldNotCrash() {
- decltype(nullptr) p; // expected-note{{'p' declared without an initial value}}
- if (getSymbol()) // expected-note {{Assuming the condition is false}}
- // expected-note@-1{{Taking false branch}}
- // expected-note@-2{{Assuming the condition is false}}
- // expected-note@-3{{Taking false branch}}
- // expected-note@-4{{Assuming the condition is true}}
- // expected-note@-5{{Taking true branch}}
- invokeF(p); // expected-warning{{1st function call argument is an uninitialized value}}
- // expected-note@-1{{1st function call argument is an uninitialized value}}
+ decltype(nullptr) p; // expected-note{{'p' initialized to a null pointer value}}
if (getSymbol()) // expected-note {{Assuming the condition is false}}
// expected-note@-1{{Taking false branch}}
// expected-note@-2{{Assuming the condition is true}}
// expected-note@-3{{Taking true branch}}
- invokeF(nullptr); // expected-note {{Calling 'invokeF'}}
- // expected-note@-1{{Passing null pointer value via 1st parameter 'x'}}
+ invokeF(p); // expected-note{{Passing null pointer value via 1st parameter 'x'}}
+ // expected-note@-1{{Calling 'invokeF'}}
+ if (getSymbol()) // expected-note {{Assuming the condition is false}}
+ // expected-note@-1{{Taking false branch}}
+ invokeF(nullptr);
if (getSymbol()) { // expected-note {{Assuming the condition is true}}
// expected-note@-1{{Taking true branch}}
X *xx = Type().x; // expected-note {{Null pointer value stored to field 'x'}}
diff --git a/test/SemaCXX/ast-print-crash.cpp b/test/SemaCXX/ast-print-crash.cpp
index c108f666d7..33edc34823 100644
--- a/test/SemaCXX/ast-print-crash.cpp
+++ b/test/SemaCXX/ast-print-crash.cpp
@@ -7,6 +7,6 @@
// CHECK: struct {
// CHECK-NEXT: } dont_crash_on_syntax_error;
-// CHECK-NEXT: decltype(nullptr) p;
+// CHECK-NEXT: decltype(nullptr) p(/*implicit*/(decltype(nullptr))0);
struct {
} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;
diff --git a/test/SemaCXX/nullptr_t-init.cpp b/test/SemaCXX/nullptr_t-init.cpp
new file mode 100644
index 0000000000..f7843de1bc
--- /dev/null
+++ b/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;
+}