
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
41 lines
913 B
Plaintext
41 lines
913 B
Plaintext
== Why is this an issue?
|
|
|
|
Contrary to what you might believe, using the addition operator does not append an integral constant to a string. Adding a ``++char++`` or an integral to a string pointer does not append it to the string. What it does instead is incrementing the string pointer by a value defined by this ``++char++`` or integral.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp]
|
|
----
|
|
int a;
|
|
std::string str1 = "foo" + a; // Noncompliant
|
|
|
|
char[] b = "foo";
|
|
char* str2 = b + 'b'; // Noncompliant{code}
|
|
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cpp]
|
|
----
|
|
int a;
|
|
std::string str1 = "foo" + std::to_string(a); // Compliant
|
|
|
|
std::string s = "foo";
|
|
std::string str2 = s + 'b'; // Compliant{code}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
adding "XXX" to a string pointer does not append to the string
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|