rspec/rules/S3685/cfamily/rule.adoc

23 lines
835 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
{cpp} allows you to append a macro value onto the end of a string literal. Prior to {cpp}11, it was possible to do this either with or without a space between the two. But with the introduction of user-defined literals in {cpp}11, the preprocessing of string suffixes changed. To get the same string + macro behavior under {cpp} 11, you must separate the string literal and the macro with a space. Without the space, you'll get a compile error.
For the purpose of preparing for migration to {cpp}11, this rule raises an issue when there's no space between a string literal and a macro.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
#define _Hrs " hours"
static const char* OPENING = "7"_Hrs; // Noncompliant
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
#define _Hrs " hours"
static const char* OPENING = "7" _Hrs; // there's one space after "7"
----