include::../description-common.adoc[]

=== Code examples

==== Noncompliant code example

[source,cpp,diff-id=1,diff-type=noncompliant]
----
a = true;
if (a) { // Noncompliant
  doSomething();
}

if (b && a) { // Noncompliant; "a" is always "true"
  doSomething();
}

if (c || !a) { // Noncompliant; "!a" is always "false"
  doSomething();
}
----

==== Compliant solution

[source,cpp,diff-id=1,diff-type=compliant]
----
a = true;
if (foo(a)) {
  doSomething();
}

if (b) {
  doSomething();
}

if (c) {
  doSomething();
}
----

== Resources

* MISRA C:2004, 13.7 - Boolean operations whose results are invariant shall not be permitted.
* MISRA C:2012, 14.3 - Controlling expressions shall not be invariant
* CWE - https://cwe.mitre.org/data/definitions/571[CWE-571 - Expression is Always True]
* CWE - https://cwe.mitre.org/data/definitions/570[CWE-570 - Expression is Always False]
* https://wiki.sei.cmu.edu/confluence/x/5dUxBQ[CERT, MSC12-C.] - Detect and remove code that has no effect or is never executed

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

include::../message.adoc[]

include::../highlighting.adoc[]

'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
