summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaInit.cpp7
-rw-r--r--clang/test/Analysis/nullptr.cpp17
-rw-r--r--clang/test/SemaCXX/ast-print-crash.cpp2
-rw-r--r--clang/test/SemaCXX/nullptr_t-init.cpp10
4 files changed, 24 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c2f14229d8d..57277f6e829 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/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
diff --git a/clang/test/Analysis/nullptr.cpp b/clang/test/Analysis/nullptr.cpp
index 38e099b7fbd..1d913c11d3c 100644
--- a/clang/test/Analysis/nullptr.cpp
+++ b/clang/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/clang/test/SemaCXX/ast-print-crash.cpp b/clang/test/SemaCXX/ast-print-crash.cpp
index c108f666d7e..33edc348230 100644
--- a/clang/test/SemaCXX/ast-print-crash.cpp
+++ b/clang/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/clang/test/SemaCXX/nullptr_t-init.cpp b/clang/test/SemaCXX/nullptr_t-init.cpp
new file mode 100644
index 00000000000..f7843de1bcb
--- /dev/null
+++ b/clang/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;
+}
OpenPOWER on IntegriCloud