No New New: Raw Pointers Removed from C++


Two weeks ago, the ISO C++ standard meeting took place in Jacksonville.  Today I want to make a short detour and write about the revolutionary decision that was made in the Jacksonville meeting. Additionally, I refer to the post C++ Will no Longer Have Pointers by Fluent C++. The standard committee decided that pointers will be deprecated in C++20 and will with very high probability be removed in C++23.

To be honest, what seems like a revolution is only the last step in a long evolution. First, let me explain the big picture.


The evolution of pointers in C++

Pointers are part of C++ since the first beginning. We got them from C. From the first beginning, there was always the tendency in C++ to make the handling with pointers more type-safe without paying the extra cost.

With C++98 we got std::auto_ptr to express exclusive ownership. But std::auto_ptr had a big issue. When you copy a std::auto_ptr the resource will be moved. What looks like a copy operation was actually a move operation. The graphic shows the surprising behaviour of an std::auto_ptr.


This was extremely bad and the reason for a lot of serious bugs; therefore, we got std::unique_ptr with C++11 and std::auto_ptr was deprecated in C++11 and finally removed in C++17. Additionally, we got std::shared_ptr and std::weak_ptr in C++11 for handling shared ownership. You can not copy but move an std::unique_ptr and if you copy or assign an std::shared_ptr, the internal reference counter will be increased. Have a look here:



Since C++11 C++ has a multithreading library. This makes the handling with std::shared_ptr quite challenging because a std::shared_ptr is per definition shared but not thread-safe. Only the control-block is thread-safe but not the access to its resource. That means, modifying the reference counter is an atomic operation and you have the guarantee that the resource will be deleted exactly once. This is the reason we will get with C++20 atomic smart pointers: std::atomic_shared_ptr and std::atmic_weak_ptr. Read the details in the proposal: Atomic Smart Pointers.

Now to the more interesting part of C++20 and C++23. Pointers will be deprecated in C++20 and removed in C++23. Or to say it with three words: No New New (NNN).

std::unique_ptr to our rescue

But hold, we have a dogma in C++: Don't pay for anything, you don't need. How can we program without a pointer? Just use an std::unique_ptr. A std::unique_ptr is by design as fast and as slim as a raw pointer but has a great benefit: it automatically manages its resource.

Only to remind you. Here is a simple performance test.

// all.cpp

#include <chrono>
#include <iostream>

static const long long numInt= 100000000;

int main(){

  auto start = std::chrono::system_clock::now();

  for ( long long i=0 ; i < numInt; ++i){
    int* tmp(new int(i));
    delete tmp;
    // std::shared_ptr<int> tmp(new int(i));
    // std::shared_ptr<int> tmp(std::make_shared<int>(i));
    // std::unique_ptr<int> tmp(new int(i));
    // std::unique_ptr<int> tmp(std::make_unique<int>(i));

  std::chrono::duration<double> dur= std::chrono::system_clock::now() - start;
  std::cout << "time native: " << dur.count() << " seconds" << std::endl;



The program allocates and deletes 100.000.000 ints.  I use a raw pointer, and std::shared_ptr and std::unique_ptr in two variations. I executed the program with and without maximum optimisation on Linux and Windows. Here are the numbers.


The numbers show it black on blue. The two variations of std::unique_ptr are on Linux and Windows as fast as the raw pointers. For the details of the numbers, read my previous post: Memory and Performance Overhead of Smart Pointers.

Ownership semantic

Honestly, we use pointers and in particular raw pointers far too often. The question if you should use a pointer, boils down to one question: Who is the owner? Luckily, we can directly express our intention about ownership in code.

  • Local objects. The C++ runtime as the owner automatically manages the lifetime of these resources. The same holds for global objects or members of a class. The guidelines call them scoped objects.
  • References: I'm not the owner. I only borrowed the resource that cannot be empty.
  • Raw pointers: I'm not the owner. I only borrowed the resource that can be can be empty. I must not delete the resource.
  • std::unique_ptr: I'm the exclusive owner of the resource. I may explicitly release the resource.
  • std::shared_ptr: I share the resource with other shared ptr. I may explicitly release my shared ownership.
  • std::weak_ptr: I'm not the owner of the resource but I may become temporary the shared owner of the resource by using the method std::weak_ptr::lock.

We have only to change our practice in one out of six use-cases and we are fine with the next evolution step in C++.

What's next?

Sorry for the detour but the Jacksonville decision was worth a detour. The next post will be about the rules to performance in the C++ Core Guidelines.

Further Information

The decision to the next pdf bundle is made. It will take me about a week to prepare the pdf-bundles. First, I have to look for typos. People already subscribed to my newsletter will get them automatically.





Thanks a lot to my Patreon Supporters: Matt Braun, Roman Postanciuc, Tobias Zindl, Marko, G Prvulovic, Reinhold Dröge, Abernitzke, Frank Grimm, Sakib, Broeserl, António Pina, Sergey Agafyin, Андрей Бурмистров, Jake, GS, Lawton Shoemake, Animus24, Jozo Leko, John Breland, espkk, Wolfgang Gärtner, Louis St-Amour, Venkat Nandam, Jose Francisco, Douglas Tinkham, Kuchlong Kuchlong, Robert Blanch, Truels Wissneth, Kris Kafka, Mario Luoni, Neil Wang, Friedrich Huber, lennonli, Pramod Tikare Muralidhara, Peter Ware, Tobi Heideman, Daniel Hufschläger, Red Trip, Alexander Schwarz, Tornike Porchxidze, Alessandro Pezzato, and Evangelos Denaxas.


Thanks in particular to Jon Hess, Lakshman, Christian Wittenhorst, Sherhy Pyton, Dendi Suhubdy, Sudhakar Belagurusamy, and Richard Sargeant.

My special thanks to Embarcadero CBUIDER STUDIO FINAL ICONS 1024 Small



I'm happy to give online-seminars or face-to-face seminars world-wide. Please call me if you have any questions.

Bookable (Online)


Standard Seminars (English/German)

Here is a compilation of my standard seminars. These seminars are only meant to give you a first orientation.


Contact Me

Modernes C++,




0 #1 Rainer Grimm 2018-04-02 06:00
Quoting Segey:
LoL! 1. April glaube ich niemandem!

Stimmt! Glaube niemand am 1. April.
0 #2 chung cu hong linh 2018-07-18 01:27
I am in fact delighted to glance at this weblog
posts which carries tons of useful facts, thanks for providing these kinds of
0 #3 bộ chăn ra gối nệm 2018-08-20 05:57
Hello! Would you mind if I share your blog with my zynga group?
There's a lot of folks that I think would really enjoy your content.
Please let me know. Many thanks
+1 #4 Rainer Grimm 2018-08-22 05:03
Quoting bộ chăn ra gối nệm:
Hello! Would you mind if I share your blog with my zynga group?
There's a lot of folks that I think would really enjoy your content.
Please let me know. Many thanks

You can share my post. Just mention my blog and my name.
0 #5 Adrian 2018-09-19 13:21

I appreciate a lot the fact that the commitee is working on ways to improve cpp safety, but I think it is an error to deprecate and than later remove pointers. I think a better solution would be to make the compiler accepts pointers only under a certain compilation flags, like, let's "--raw-pointers-on".
There will be ALWAYS high speed computation use case where the fast the best. ALWAYS.
If guy from, let's say, MISRA don't like pointers, just tell them to put this flag on their rules.

0 #6 Ivan 2019-03-20 21:47
Keep on working, great job!
+4 #7 ozeitu 2019-05-19 04:01
"C++ Will No Longer Have Pointers" is an april fools' joke...
+1 #8 Roland Hughes 2019-12-04 14:35
Stumbling across this site was a pleasant surprise. Removal of pointers is going to break an ocean of code. It will also mean C++ can no longer be used for low level development, particularly where hardware must be accessed via address and data transferred to it via memcpy(). It will also devastate one of the most popular cross platform toolkits out there.
+4 #9 Brian 2020-07-12 06:24
You really should edit with a note about the April fool's joke. Google is putting this in top few results for "Modern C++ Pointers"

My Newest E-Books

Course: Modern C++ Concurrency in Practice

Course: C++ Standard Library including C++14 & C++17

Course: Embedded Programming with Modern C++

Course: Generic Programming (Templates)

Course: C++ Fundamentals for Professionals

Subscribe to the newsletter (+ pdf bundle)

Blog archive

Source Code


Today 78

Yesterday 5090

Week 41524

Month 101153

All 6329625

Currently are 175 guests and no members online

Kubik-Rubik Joomla! Extensions

Latest comments