---
title: "More compile-time checks with std::nullptr_t"
url: https://daily.dev/posts/more-compile-time-checks-with-std-nullptr-t-obbwlyvr2
source_url: https://andreasfertig.com/blog/2026/08/more-compile-time-checks-with-stdnullptr_t
type: article
source: "Andreas Fertig"
published: 2026-08-04T08:43:54.480Z
updated: 2026-08-04T08:44:12.979Z
tags: ["c++"]
reading_time: 2
upvotes: 1
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# More compile-time checks with std::nullptr_t

**[Andreas Fertig](https://daily.dev/sources/andreasfertig)** · 2 min read · 1 upvotes · 0 comments

## Summary

std::nullptr_t is a C++11 type that holds exactly the nullptr value. By adding a deleted constructor accepting std::nullptr_t to classes like std::string, you can catch undefined behavior (constructing a string from nullptr) at compile-time rather than relying solely on runtime assertions. C++23 already applies this pattern to std::string and std::string_view. C++26 further improves this by allowing deleted functions to carry a message explaining why they were deleted.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://andreasfertig.com/blog/2026/08/more-compile-time-checks-with-stdnullptr_t>

## Similar posts on daily.dev

- [C\+\+26: Reducing undefined behaviour](https://daily.dev/posts/c-26-reducing-undefined-behaviour-tbbsne1hb) · Sandor Dargo · 0 upvotes · 0 comments
- [Forward declaring a type in C\+\+: The good, and the bad](https://daily.dev/posts/forward-declaring-a-type-in-c-the-good-and-the-bad-myagfsifh) · Andreas Fertig · 1 upvotes · 2 comments

---

Tags: [#c++](https://daily.dev/tags/c++)

[View this post on daily.dev](https://daily.dev/posts/more-compile-time-checks-with-std-nullptr-t-obbwlyvr2)
