Skip to content

Commit c157b5e

Browse files
committed
Fix nullptr support again, remove custom implementation
1 parent 8f5868d commit c157b5e

File tree

9 files changed

+37
-17
lines changed

9 files changed

+37
-17
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99
### Added
10+
- Proper `ostream operator <<` for `nullptr`
11+
- Proper comparison operations fro `nullptr`
1012

1113
### Changed
1214

1315
### Deprecated
1416

1517
### Removed
18+
- Homegrown implementation of `nullptr`
1619

1720
### Fixed
21+
- `nullptr` support (again)
1822

1923
### Security
2024

SampleProjects/TestSomething/test-something.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ int testSomething(void) {
33
millis(); // this line is only here to test that we're able to refer to the builtins
44
return 4;
55
};
6+
7+
int* aNullPointer(void) {
8+
int* ret = nullptr;
9+
return ret;
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#pragma once
22
#include <Arduino.h>
33
int testSomething(void);
4+
int *aNullPointer(void);

SampleProjects/TestSomething/test/library.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ unittest(library_tests_something)
66
assertEqual(4, testSomething());
77
}
88

9+
unittest(library_returns_nullptr)
10+
{
11+
assertEqual(nullptr, aNullPointer());
12+
}
13+
914
unittest_main()

cpp/arduino/Arduino.h

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Where possible, variable names from the Arduino library are used to avoid confli
1515
#include "Stream.h"
1616
#include "HardwareSerial.h"
1717
#include "SPI.h"
18-
#include "Nullptr.h"
1918

2019
typedef bool boolean;
2120
typedef uint8_t byte;

cpp/arduino/Nullptr.h

-7
This file was deleted.

cpp/unittest/ArduinoUnitTests.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "OstreamHelpers.h"
34
#include "Assertion.h"
45
#include <iostream>
56
using namespace std;

cpp/unittest/Compare.h

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22
#include <avr/pgmspace.h>
33
#include <WString.h>
4-
#include <Nullptr.h>
54

65
template < typename A, typename B > struct Compare
76
{
@@ -899,14 +898,22 @@ template < size_t N, size_t M > struct Compare<char [N],char [M]>
899898
} // moreOrEqual
900899
};
901900

902-
// null pointer comparisons
903-
template <typename B> int compareBetween( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::between( a, b); }
904-
template <typename B> bool compareEqual( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::equal( a, b); }
905-
template <typename B> bool compareNotEqual( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::notEqual( a, b); }
906-
template <typename B> bool compareLess( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::less( a, b); }
907-
template <typename B> bool compareMore( const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::more( a, b); }
908-
template <typename B> bool compareLessOrEqual(const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::lessOrEqual(a, b); }
909-
template <typename B> bool compareMoreOrEqual(const my_nullptr_t &a, const B &b) { return Compare<my_nullptr_t,B>::moreOrEqual(a, b); }
901+
// null pointer comparisons to other stuff
902+
template <typename A> int compareBetween( const A &a, const std::nullptr_t &b) { return a ? -1 : 0; }
903+
template <typename A> bool compareEqual( const A &a, const std::nullptr_t &b) { return !a; }
904+
template <typename A> bool compareNotEqual( const A &a, const std::nullptr_t &b) { return a; }
905+
template <typename A> bool compareLess( const A &a, const std::nullptr_t &b) { return false; }
906+
template <typename A> bool compareMore( const A &a, const std::nullptr_t &b) { return a; }
907+
template <typename A> bool compareLessOrEqual(const A &a, const std::nullptr_t &b) { return !a; }
908+
template <typename A> bool compareMoreOrEqual(const A &a, const std::nullptr_t &b) { return true; }
909+
910+
template <typename B> int compareBetween( const std::nullptr_t &a, const B &b) { return b ? 1 : 0; }
911+
template <typename B> bool compareEqual( const std::nullptr_t &a, const B &b) { return !b; }
912+
template <typename B> bool compareNotEqual( const std::nullptr_t &a, const B &b) { return b; }
913+
template <typename B> bool compareLess( const std::nullptr_t &a, const B &b) { return b; }
914+
template <typename B> bool compareMore( const std::nullptr_t &a, const B &b) { return false; }
915+
template <typename B> bool compareLessOrEqual(const std::nullptr_t &a, const B &b) { return true; }
916+
template <typename B> bool compareMoreOrEqual(const std::nullptr_t &a, const B &b) { return !b; }
910917

911918
// super general comparisons
912919
template <typename A, typename B> int compareBetween( const A &a, const B &b) { return Compare<A,B>::between( a, b); }

cpp/unittest/OstreamHelpers.h

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <ostream>
4+
5+
inline std::ostream& operator << (std::ostream& out, const std::nullptr_t &np) { return out << "nullptr"; }

0 commit comments

Comments
 (0)