Modify rule S4962: LaYC format

This commit is contained in:
Fred Tingaud 2023-09-28 15:21:02 +02:00 committed by GitHub
parent f1c356477b
commit 03a7ce526c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,44 +1,35 @@
== Why is this an issue?
Before {cpp}11, the only way to refer to a null pointer was by using the integer literal ``++0++``, which created ambiguity with regard to whether a pointer or an integer was intended. Even with the ``++NULL++`` macro, the underlying value is still ``++0++``.
Before {cpp}11, the only way to refer to a null pointer was by using the integer literal ``++0++``, which created ambiguity about whether a pointer or an integer was intended. Even with the ``++NULL++`` macro, the underlying value is still ``++0++``.
{cpp}11 introduced the keyword ``++nullptr++``, which is unambiguous and should be used systematically.
=== Noncompliant code example
{cpp}11 introduced the keyword ``++nullptr++``, which unambiguously refers to the null pointer. It should be used systematically.
[source,cpp]
----
void f(char *c);
void g(int i);
void h()
void g(int);
void usage()
{
f(0); // Noncompliant
f(NULL); // Noncompliant
f(nullptr); // Compliant: unambiguous
g(0); // Compliant, a real integer
g(NULL); // Noncompliant, NULL should not be used for a real integer
}
----
=== Compliant solution
[source,cpp]
----
void f(char *c);
void g(int i);
void h()
{
f(nullptr); // Compliant
g(0); // Compliant, a real integer
// g(nullptr); // This would not compile
}
----
== Resources
* https://github.com/isocpp/CppCoreGuidelines/blob/036324/CppCoreGuidelines.md#es47-use-nullptr-rather-than-0-or-null[{cpp} Core Guidelines ES.47] - Use nullptr rather than 0 or NULL
=== Documentation
* {cpp} reference - https://en.cppreference.com/w/cpp/language/nullptr[nullptr]
=== External coding guidelines
* {cpp} Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/036324/CppCoreGuidelines.md#es47-use-nullptr-rather-than-0-or-null[ES.47 - Use nullptr rather than 0 or NULL]
ifdef::env-github,rspecator-view[]