rspec/rules/S3358/cfamily/rule.adoc

42 lines
953 B
Plaintext
Raw Normal View History

== Why is this an issue?
:noncompliant: cfamily/noncompliant.adoc
:compliant: cfamily/compliant.adoc
2020-06-30 12:48:39 +02:00
include::../description.adoc[]
=== Exceptions
2020-06-30 12:48:39 +02:00
In {cpp}11, the rule ignores ternary operators inside `constexpr` functions.
2020-06-30 12:48:39 +02:00
Indeed, in {cpp}11, such functions are limited to just a return statement, so using a ternary operator might be required. Later standards lifted this restriction, so this exception does not apply to them.
2020-06-30 12:48:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2020-06-30 12:48:39 +02:00
----
constexpr int max(int p1, int p2, int p3) {
return p1 > p2 ? (p1 > p3 ? p1 : p3) : (p2 > p3 ? p2 : p3); // Compliant by exception in C++11
2020-06-30 12:48:39 +02:00
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Extract this nested conditional operator into an independent statement.
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]