Initial steps to improve diagnostics when there is a NULL and
a non-pointer on the two sides of a conditional expression.

Patch by Stephen Hines and Mihai Rusu.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125995 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Sema/conditional-expr.c b/test/Sema/conditional-expr.c
index 6e248bc..7a8c9e9 100644
--- a/test/Sema/conditional-expr.c
+++ b/test/Sema/conditional-expr.c
@@ -75,3 +75,16 @@
   // We can suppress this because the immediate context wants an int.
   return (x != 0) ? 0U : x;
 }
+
+#define NULL (void*)0
+
+void PR9236() {
+  struct A {int i;} A1;
+  (void)(1 ? A1 : NULL); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}}
+  (void)(1 ? NULL : A1); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}}
+  (void)(1 ? 0 : A1); // expected-error{{incompatible operand types}}
+  (void)(1 ? (void*)0 : A1); // expected-error{{incompatible operand types}}
+  (void)(1 ? A1: (void*)0); // expected-error{{incompatible operand types}}
+  (void)(1 ? A1 : (NULL)); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}}
+}
+
diff --git a/test/SemaCXX/__null.cpp b/test/SemaCXX/__null.cpp
index 3583655..1989a45 100644
--- a/test/SemaCXX/__null.cpp
+++ b/test/SemaCXX/__null.cpp
@@ -12,3 +12,10 @@
   // Verify that null is evaluated as 0.
   int b[__null ? -1 : 1];
 }
+
+struct A {};
+
+void g() {
+  (void)(0 ? __null : A()); // expected-error {{non-pointer operand type 'A' incompatible with NULL}}
+  (void)(0 ? A(): __null); // expected-error {{non-pointer operand type 'A' incompatible with NULL}}
+}
diff --git a/test/SemaCXX/conditional-expr.cpp b/test/SemaCXX/conditional-expr.cpp
index 8ac0a97..3881765 100644
--- a/test/SemaCXX/conditional-expr.cpp
+++ b/test/SemaCXX/conditional-expr.cpp
@@ -307,3 +307,15 @@
   }
 
 }
+
+namespace PR9236 {
+#define NULL 0L
+  void f() {
+    (void)(true ? A() : NULL); // expected-error{{non-pointer operand type 'A' incompatible with NULL}}
+    (void)(true ? NULL : A()); // expected-error{{non-pointer operand type 'A' incompatible with NULL}}
+    (void)(true ? 0 : A()); // expected-error{{incompatible operand types}}
+    (void)(true ? nullptr : A()); // expected-error{{non-pointer operand type 'A' incompatible with nullptr}}
+    (void)(true ? __null : A()); // expected-error{{non-pointer operand type 'A' incompatible with NULL}}
+    (void)(true ? (void*)0 : A()); // expected-error{{incompatible operand types}}
+  }
+}
diff --git a/test/SemaCXX/nullptr.cpp b/test/SemaCXX/nullptr.cpp
index 666701c..7385fd4 100644
--- a/test/SemaCXX/nullptr.cpp
+++ b/test/SemaCXX/nullptr.cpp
@@ -46,6 +46,8 @@
   (void)(1 + nullptr); // expected-error {{invalid operands to binary expression}}
   (void)(0 ? nullptr : 0); // expected-error {{incompatible operand types}}
   (void)(0 ? nullptr : (void*)0);
+  (void)(0 ? nullptr : A()); // expected-error {{non-pointer operand type 'A' incompatible with nullptr}}
+  (void)(0 ? A() : nullptr); // expected-error {{non-pointer operand type 'A' incompatible with nullptr}}
 
   // Overloading
   int t = o1(nullptr);