From 9fb043ba6503315ccf7de240f1b635f94f503bb2 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 25 Mar 2018 09:19:35 +0200 Subject: [PATCH] Fix typeof(null) being a pointer for isPointer --- source/tanya/meta/package.d | 2 +- source/tanya/meta/trait.d | 15 ++++++++++++++- source/tanya/meta/transform.d | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/source/tanya/meta/package.d b/source/tanya/meta/package.d index 568a24f..d93e4fa 100644 --- a/source/tanya/meta/package.d +++ b/source/tanya/meta/package.d @@ -9,7 +9,7 @@ * to transform from one type to another. It has also different algorithms for * iterating, searching and modifying template arguments. * - * Copyright: Eugene Wissner 2017. + * Copyright: Eugene Wissner 2017-2018. * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * Mozilla Public License, v. 2.0). * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) diff --git a/source/tanya/meta/trait.d b/source/tanya/meta/trait.d index f62b19a..53f488e 100644 --- a/source/tanya/meta/trait.d +++ b/source/tanya/meta/trait.d @@ -735,7 +735,7 @@ template isPointer(T) { static if (is(T U : U*)) { - enum bool isPointer = true; + enum bool isPointer = !is(Unqual!(OriginalType!T) == typeof(null)); } else { @@ -752,6 +752,19 @@ template isPointer(T) static assert(!isPointer!bool); } +// typeof(null) is not a pointer. +@nogc nothrow pure @safe unittest +{ + static assert(!isPointer!(typeof(null))); + static assert(!isPointer!(const shared typeof(null))); + + enum typeOfNull : typeof(null) + { + null_ = null, + } + static assert(!isPointer!typeOfNull); +} + /** * Determines whether $(D_PARAM T) is an array type (dynamic or static, but * not an associative one). diff --git a/source/tanya/meta/transform.d b/source/tanya/meta/transform.d index 5d4a50b..7d6170d 100644 --- a/source/tanya/meta/transform.d +++ b/source/tanya/meta/transform.d @@ -9,7 +9,7 @@ * types. They take some type as argument and return a different type after * perfoming the specified transformation. * - * Copyright: Eugene Wissner 2017. + * Copyright: Eugene Wissner 2017-2018. * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * Mozilla Public License, v. 2.0). * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)