Skip to content

Commit 1af6957

Browse files
committed
M5-3-1: Exclude unknown types
This ensures we consistently exclude unknown results for unevaluated contexts in uninstantiated templates.
1 parent 97fabeb commit 1af6957

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `M5-3-1` - `EachOperandOfTheOperatorOfTheLogicalAndOrTheLogicalOperatorsShallHaveTypeBool.ql`:
2+
- Consistently exclude results in unevaluated contexts associated with uninstantiated templates, for example `noexcept` specifiers and `static_assert`s.

Diff for: cpp/autosar/src/rules/M5-3-1/EachOperandOfTheOperatorTheLogicalAndOrTheLogicalOperatorsShallHaveTypeBool.ql

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ where
2525
) and
2626
t = operand.getType() and
2727
not t.getUnderlyingType().getUnspecifiedType() instanceof BoolType and
28+
// Ignore cases where the type is unknown - this will typically be in unevaluated contexts
29+
// within uninstantiated templates. It's necessary to check for this explicitly because
30+
// not all unevaluated contexts are considered to be `isFromUninstantiatedTemplate(_)`,
31+
// e.g. `noexcept` specifiers
32+
not t instanceof UnknownType and
2833
not exists(ReferenceType rt |
2934
rt = t.getUnderlyingType().getUnspecifiedType() and rt.getBaseType() instanceof BoolType
3035
) and

Diff for: cpp/autosar/test/rules/M5-3-1/test.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,13 @@ template <typename T = int> class A {
2525
void f() {
2626
A<int> a;
2727
a.test1();
28-
}
28+
}
29+
30+
template <typename T> constexpr bool some_variable_template_v = false;
31+
template <> constexpr bool some_variable_template_v<int> = true;
32+
33+
template <typename S>
34+
void template_with_no_except() noexcept(some_variable_template_v<S> &&
35+
true) { // COMPLIANT
36+
}
37+
void test_template() { template_with_no_except<int>(); }

0 commit comments

Comments
 (0)