Document number P2657R1
Date 2022-11-14

Jarrad J. Waterloo <descender76 at gmail dot com>

Audience Evolution Working Group (EWG)

C++ is the next C++

Table of contents




Programmer’s, Businesses and Government(s) want C++ to be safer and simpler. This has led some C++ programmers to create new programming languages or preprocessors, which again is a new language. This paper discusses using static analysis to make the C++ language itself safer and simpler.

Motivating Examples

Following is a wishlist. Most are optional. While, they all would be of benefit. It all starts with a new module level attribute that would preferably be applied once in the primary module interface unit and would automatically apply to it and all module implementation unit(s). It could also be applied to a module implementation unit but that would generally be less useful. However, it might aid in gradual migration.

export module some_module_name [[static_analysis(inclusions{"", "", ""}, exclusions{"", "", ""})]];// primary module interface unit
// or
module some_module_name [[static_analysis(inclusions{"", "", ""}, exclusions{"", "", ""})]];// module implementation unit

The names of the inclusions and exclusions are dotted. Unscoped or names that start with std., c++., cpp., cxx. or c. are reserved for standardization.

This proposal wants to stardardize two overarching static analyzer names; safer and modern.


The safer analyzer is for safety, primarily memory related. It is for those businesses and programmers who must conform to safety standards. The safer analyzer is a subset of modern analyzer.


The modern analyzer goes beyond just memory and safety concerns. It can be thought of as bleeding edge. It is for those businesses and programmers who commit to safety and higher quality modern code. That is those who want to enjoy the full benefits that C++ has to offer.

Neither is concerned about formatting or nitpicking. Both static analyzers only produce errors. These are meant for programmers, businesses and governments in which safety takes precedence. They both represent +∞; an ever increasing commitment. When a new version of the standard is released and adds new sub static analyzers than everyone’s code is broken, until their code is fixed. These sub static analyzers usually consist of features that have been mostly replaced with some other feature. It would be ideal if the errors produced not only say that the code is wrong but also provide a link to html page(s) maintained by the C++ teaching group, the authors of the C++ Core Guidelines [1] and compiler specific errors. These pages should provide example(s) of what is being replaced and by what was it replaced. Mentioning the version of the C++ standard would also be helpful.

All modules can be used even if they don’t use the static_analysis attribute as this allows gradual adoption.

The resolved list of static analyzers that will run is derived by first taking the union of all of the included analyzers including their component analyzers and removing from that union the union of all the excluded ananlyzers and their component analyzers.

resolved = (inclusion ∪ inclusion ∪ inclusion) - (exclusion ∪ exclusion ∪ exclusion)

This allows the programmer to exclude a few analyzers from a larger grouping instead of having to list out almost all the ever growing number of smaller analyzers that comprise the larger ones.

[[static_analysis(inclusions{"modern"}, exclusions{"use_ranges"})]];

What are the safer and modern analyzers composed of?

These overarching static analyzers are composed of multiple static analyzers which can be used individually to allow a degree of gradual adoption.

Use lvalue references


use_lvalue_references is a subset of safer.


lvalue references

1985: Cfront 1.0 [2]


1992 [2:1]

std::unique_ptr, std::shared_ptr, std::weak_ptr, std::reference_wrapper, std::make_shared




std::string_view, std::optional, std::any, std::variant


std::make_shared support arrays, std::span


The C++ Core Guidelines [1:1] identifies issues that this feature helps to mitigate.


Usage of smart pointers

This static analyzer causes programmers to use 2 extra characters when using smart pointers, -> vs (*)., since the overloaded -> operator returns a pointer.

smart_pointer->some_function();// bad
(*smart_pointer).some_function();// good

the main function and environment variables

A shim module is needed in order to transform main and env functions into a more C++ friendly functions. These have been asked for years.

  1. A Modern C++ Signature for main [52]
  2. Desert Sessions: Improving hostile environment interactions [53]

No unsafe casts


no_unsafe_casts is a subset of safer.


The C++ Core Guidelines [1:2] identifies issues that this feature helps to mitigate.

No unions


no_union is a subset of safer.

It was replaced by std::variant, which is safer.

The C++ Core Guidelines [1:3] identifies issues that this feature helps to mitigate.

No mutable


no_mutable is a subset of safer.

The programmer shall not lie to oneself. The mutable keyword violates the safety of const and is rarely used at a high level.

No new or delete


no_new_delete is a subset of safer.

It was replaced by std::make_unique and std::make_shared, which are safer.

The C++ Core Guidelines [1:4] identifies issues that this feature helps to mitigate.

No volatile


no_volatile is a subset of safer.

The volatile keyword has nothing to do with concurrency. Use std::atomic or std::mutex instead.

The C++ Core Guidelines [1:5] identifies issues that this feature helps to mitigate.

No C style variadic functions


no_c_style_variadic_functions is a subset of safer.

C style variadic functions has been replaced by overloading, templates and variadic template functions.

The C++ Core Guidelines [1:6] identifies issues that this feature helps to mitigate.

No deprecated


no_deprecated is a subset of modern.

Deprecated functionality is not modern.

Use std::array


use_std_array is a subset of modern.

Use std::array instead of C style/core C++ array.

Use ranges


use_ranges is a subset of modern.

Using any iterator based algorithm that has been replaced with a range based algorithm produces an error informing the programmer to use the range based algorithm instead.

What may safer and modern analyzers be composed of in the future?

No include


no_include is a subset of modern.

The preprocessor directive #include has been replaced with import. Don’t add the static analyzer until #embed is added.

NOTE: This may be impossible to implement as preprocessing occurs before compilation.

No goto


no_goto is a subset of modern.

Don’t add until break and continue to a label is added. Also a really easy to use finite state machine library may be needed.

The C++ Core Guidelines [1:7] identifies issues that this feature helps to mitigate.

Use std::function_ref


use_function_ref is a subset of safer.

Use std::function_ref instead of C style/core C++ [member] function pointers. std::function_ref can bind to stateful and stateless, free and member functions. It saves programmers from having to include a void* state parameter in their function pointer types and it also saves from having to include void* state parameter along side the function pointer type in each function where the function pointer type is used in function declarations. Neither of which could be performed with the "use_lvalue_references" static analyzer.


Tooling Opportunities

Automated Code Reviews

In the Motivating Examples section there were two specific wishlist items.

With these capabilities, a report could be created during a distributed version control system’s pull/merge request. The report could be compared to the report of the destination of the request. If the changed code is not better than the existing code than the request can be automatically rejected. This would result in an adaptation of the boy scout rule.

Leave the code cleaner than you found it.

Consequently, this results in the creation of a programmer incline. With each checkin, the code gets better. The incline can even be adjusted by requiring how much better one must leave the code.

Reserved Behavior

The static_analysis attribute can only, for now, be used on either primary module interface unit or module implementation unit but not both at the same time. Enabling it in both would require a discussion of how these analyzers should combine. Which one would take precedence? It would need to be part of a larger discussion of whether the static_analysis attribute could be applied at the namespace, class, function or control block levels. This proposal is focused on the module level as current static analyzers on the market is more focused on the translation unit level rather than on a per line basis. As such, this proposal could be adopted faster, yet, leaving room for improvements, once static analyzers improve in their precision.


By adding static analysis to the C++ language we can make the language safer and easier to teach because we can restrict how much of the language we use. Human readable errors and references turns the compiler into a teacher freeing human teachers to focus on what the compiler doesn’t handle.

Frequently Asked Questions

Shouldn’t these be warnings instead of errors?

NO, otherwise we’ll be stuck with what we just have. C++ compilers produces plenty of warnings. C++ static analyzers produces plenty of warnings. However, when some one talks about creating a new language, then old language syntax becomes invalid i.e. errors. This is for programmers. Programmers and businesses rarely upgrade their code unless they are forced to. Businesses and Government(s) want errors, as well, in order to ensure code quality and the assurance that bad code doesn’t exist anywhere in the module. This is also important from a language standpoint because we are essentially pruning; somewhat. Keep in mind that all of these pruned features still have use now. In the future, more constructs will be built upon these pruned features. This is why they need to be part of the language, just not a part of everyday usage of the language.

Why at the module level? Why not safe and unsafe blocks?

Programmers and businesses rarely upgrade their code unless they are forced to. New programmers need training wheels and some of us older programmers like them too. Due to the proliferation of government regulations and oversight, businesses have acquired software composition analysis services and tools. These services map security errors to specific versions of modules; specifically programming artifacts such as executables and libraries. As such, businesses want to know if a module is reasonably safe.

You must really hate pointers?

Actually, I love C, C++ and pointers.

The fact is pointers, unsafe casts, union, mutable and goto are the engine of C++ change. As such it would be foolish to remove them but it is also unrealistic for users/drivers of a vehicle to have to drive with nothing between them and the engine, without listening to them clamor for interior finishing.

C++ can’t standardize specific static analyzers

Do you fear that this could create a “subset of C++” that “could split the user community and cause acrimony”? [65]

First of all, let’s consider the quotes of Bjarne Stroustrup that this question are based upon.

“being defined by an ‘industry consortium.’ I am not in favor of language subsets or dialects. I am especially not fond of subsets that cannot support the standard library so that the users of that subset must invent their own incompatible foundation libraries. I fear that a defined subset of C++ could split the user community and cause acrimony” [65:1]

Does this paper create a subset? YES. Like it or not C++ already have a couple of subsets; some positive, some quasi. Freestanding is a subset for low level programming. This proposal primarily focus on high level programming but there is nothing preventing the creation of [[static_analysis(inclusions{"freestanding"})]] which enforces freestanding. The C++ value categories has to some degree fractured the community into a clergy class that thoroughly understand its intracacies and a leity class that gleefully uses it.

Does this paper split the user community? YES and NO. It splits code into safer vs. less safe, high level vs. low level. However, this is performed at the module level, allowing the same programmer to decide what falls on either side of the fence. This would not be performed by an industry consortium but rather the standard. Safer modules can be used by less safe modules. Less safe modules can partly be used by safer modules, such as with the standard module. This latter impact is already minimalized because the standard frequently write their library code in C++ fashion instead of a C fashion.

“Are there any features you’d like to remove from C++?” [66]

Not really. People who ask this kind of question usually think of one of the major features such as multiple inheritance, exceptions, templates, or run-time type identification. C++ would be incomplete without those. I have reviewed their design over the years, and together with the standards committee I have improved some of their details, but none could be removed without doing damage. [66:1]

Most of the features I dislike from a language-design perspective (e.g., the declarator syntax and array decay) are part of the C subset of C++ and couldn’t be removed without doing harm to programmers working under real-world conditions. C++'s C compatibility was a key language design decision rather than a marketing gimmick. Compatibility has been difficult to achieve and maintain, but real benefits to real programmers resulted, and still result today. By now, C++ has features that allow a programmer to refrain from using the most troublesome C features. For example, standard library containers such as vector, list, map, and string can be used to avoid most tricky low-level pointer manipulation. [66:2]

The beauty of this proposal is it does not and it does remove features from C++. Like the standard library, it allows programmers to refrain from using the most troublesome C and C++ features.

“Within C++, there is a much smaller and cleaner language struggling to get out” [67]

Both making things smaller and cleaner requires removing something. When creating a new language, removing things happens extensively at the beginning but, frequently, features have to be added back in, when programmers clamor for them. This paper cleans up a programmers use of the C++ language, meaning less C++ has to be taught immediately, thus making things simpler. As a programmer matures, features can be gradually added to their repertoire, just as it was added to ours. After all, isn’t C++ larger now, than when we started programming in C++.

How does this relate to p2687r0: Design Alternatives for Type-and-Resource Safe C++?

This proposal and the “Design Alternatives for Type-and-Resource Safe C++” [68] proposal both recommend that static analysis be used and brought into the language instead of inventing a whole new language. Both tackles problems in its own way. Either proposal could be enhanced to do what the other proposal does. The question is what are these differences and should these be given some attention.

Different audiences

This proposal might appeal more to non voting, newer programmers working on smaller, newer code bases. The p2687r0 proposal appeals more to voting, older programmers working on larger, older code bases. There are also differences in the sizes of these two audiences. This proposal would have the larger audience as it appeals to those who want a subset of language and library features. There are also differences in the level of coding. This proposal favors high level, abstraction heavy coding. The p2687r0 proposal appeals more to lower level, closer to hardware coding. Again both proposals fixes safety issues and either audience just wants more safety, sooner, rather than later.

Are there any elements of this proposal that would still appeal to lower level coders? New code does get developed in older code bases. The question is do you want programmers to keep writing their code the old way for the sake of a foolish consistency! So this proposal is of use to lower level programmers. With the p2687r0 proposal, a lot of time is spent analyzing and documenting with attributes the intention of pointers at each point of use in the code. No rewrite is being performed and more information is being provided to resolve ambiguity for the benefit of the static analyzer. The cost of this programmer analysis and attributing can be most of the cost of a rewrite, so why not just rewrite it incrementally in safer modern C++! This proposal helps even with this. From my experience with lower level code, I tend to have a few files of the majority that does the work with memory mapped files or that call C API’s but once I have my wrappers, the remainer of my code is very high level and abstract. So in this regard, this proposal is of benefit. C++20 modules are still new even to existing code bases especially since tool chains are still being developed and their are still many unanswered questions. Since there will need to be incremental refactoring to use modules in older code bases, why not take advantage of this proposal’s module level attribute to take advantage of more refactoring.

Different scopes

This proposal has fewer features than p2687r0. For instance, it currently only works at the module level. This is similar to where many static analyzers run, at the translation unit level. While this proposal has far fewer features, it is smaller, simpler and easier to implement. This could mean the difference in getting some subset of safety in the C++26/C++29 timeframe instead of the C++29/C++32 timeframe. The additional features could be added incrementally.

Different solutions

The p2687r0 proposal tackles problems head on. Bravo! This proposal is about avoiding problems, all together, by using existing language and library features, that we have had for years, if not decades, but just needed the option of enforcement. Both, I know, have merit. Some problems are left by this proposal deliberately to other proposals.

For instance, on the subject of dangling, it is best to fix more of this in the language instead of the analyzer. With the following two proposals, the dangling mountain could be shrunk to a mole-hill or ant-hill.

Further adding the paper that those two were based on would further shrink dangling to a few grains of sand on a sea shore of code.

On the subject of type safety, this paper agrees with the p2687r0 proposal on the usage of SELL, Semantically Enhanced Language Libraries. Currently, there is work ongoing in the standardization process to provide a standard units library which would go a long ways for type safety. Currently, there is work ongoing in the standardization process to provide a standard graph library which would go a long ways for the more extreme memory safety. Still unproposed but still needed are strongly typed alias library or language features for safer int(s). Enhancements to existing fundamental types in C++ could include validation and tag classes in order to make those types safer.

In short, this proposal is, in some ways, a subset of the p2687r0 proposal. Combined with other proposals, they beat the most notorious safety problems into an acceptable level of safety to many.


Thanks to Vladimir Smirnov for providing very valuable feedback on this proposal.


  1. ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎

  2. ↩︎ ↩︎

  3. ↩︎

  4. ↩︎

  5. ↩︎

  6. ↩︎

  7. ↩︎

  8. ↩︎

  9. ↩︎

  10. ↩︎

  11. ↩︎

  12. ↩︎

  13. ↩︎

  14. ↩︎

  15. ↩︎

  16. ↩︎

  17. ↩︎

  18. ↩︎

  19. ↩︎

  20. ↩︎ ↩︎

  21. ↩︎ ↩︎

  22. ↩︎

  23. ↩︎

  24. ↩︎

  25. ↩︎

  26. ↩︎

  27. ↩︎ ↩︎

  28. ↩︎ ↩︎

  29. ↩︎ ↩︎

  30. ↩︎

  31. ↩︎

  32. ↩︎

  33. ↩︎

  34. ↩︎

  35. ↩︎ ↩︎

  36. ↩︎

  37. ↩︎

  38. ↩︎

  39. ↩︎

  40. ↩︎ ↩︎

  41. ↩︎ ↩︎

  42. ↩︎ ↩︎

  43. ↩︎

  44. ↩︎

  45. ↩︎

  46. ↩︎

  47. ↩︎ ↩︎

  48. ↩︎ ↩︎

  49. ↩︎

  50. ↩︎

  51. ↩︎

  52. ↩︎

  53. ↩︎

  54. ↩︎

  55. ↩︎

  56. ↩︎

  57. ↩︎

  58. ↩︎

  59. ↩︎

  60. ↩︎

  61. ↩︎

  62. ↩︎

  63. ↩︎

  64. ↩︎

  65. ↩︎ ↩︎

  66. ↩︎ ↩︎ ↩︎

  67. ↩︎

  68. ↩︎

  69. ↩︎

  70. ↩︎

  71. ↩︎

  72. ↩︎