rspec/rules/S3685/cfamily/rule.adoc

52 lines
1.2 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
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.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
#define _Hrs " hours"
static const char* OPENING = "7"_Hrs; // Noncompliant
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
#define _Hrs " hours"
static const char* OPENING = "7" _Hrs; // there's one space after "7"
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add a space after this string literal.
=== Highlighting
string literal
'''
== Comments And Links
(visible only on this page)
=== on 26 Jul 2016, 16:07:20 Ann Campbell wrote:
I've made a few more changes [~alban.auzeill]
endif::env-github,rspecator-view[]