Skip to content

Commit 6a6fc7f

Browse files
authored
Merge pull request #844 from github/lcartey/a7-1-2-remove-funcs
`A7-1-2`: Do not report function candidates for `constexpr`
2 parents 2acc92a + 07cea2a commit 6a6fc7f

File tree

8 files changed

+23
-355
lines changed

8 files changed

+23
-355
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A7-1-2` - `FunctionMissingConstexpr.ql`
2+
- Address false positives by removing the query - the rule is not intended to cover functions.

cpp/autosar/src/rules/A7-1-2/FunctionMissingConstexpr.ql

-160
This file was deleted.

cpp/autosar/test/rules/A7-1-2/FunctionMissingConstexpr.expected

-16
This file was deleted.

cpp/autosar/test/rules/A7-1-2/FunctionMissingConstexpr.qlref

-1
This file was deleted.

cpp/autosar/test/rules/A7-1-2/VariableMissingConstexpr.expected

+14-13
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
| test.cpp:44:16:44:17 | lc | Variable 'lc' could be marked 'constexpr'. |
99
| test.cpp:45:17:45:19 | lc2 | Variable 'lc2' could be marked 'constexpr'. |
1010
| test.cpp:55:7:55:8 | m2 | Variable 'm2' could be marked 'constexpr' and static. |
11-
| test.cpp:130:7:130:8 | m1 | Variable 'm1' could be marked 'constexpr' and static. |
12-
| test.cpp:141:7:141:8 | m1 | Variable 'm1' could be marked 'constexpr' and static. |
13-
| test.cpp:221:7:221:8 | l1 | Variable 'l1' could be marked 'constexpr'. |
14-
| test.cpp:235:7:235:8 | l6 | Variable 'l6' could be marked 'constexpr'. |
15-
| test.cpp:237:7:237:8 | l8 | Variable 'l8' could be marked 'constexpr'. |
16-
| test.cpp:240:7:240:9 | l10 | Variable 'l10' could be marked 'constexpr'. |
17-
| test.cpp:243:7:243:9 | l12 | Variable 'l12' could be marked 'constexpr'. |
18-
| test.cpp:248:7:248:9 | l15 | Variable 'l15' could be marked 'constexpr'. |
19-
| test.cpp:250:7:250:9 | l16 | Variable 'l16' could be marked 'constexpr'. |
20-
| test.cpp:251:7:251:9 | l17 | Variable 'l17' could be marked 'constexpr'. |
21-
| test.cpp:257:7:257:9 | l21 | Variable 'l21' could be marked 'constexpr'. |
22-
| test.cpp:262:7:262:9 | l24 | Variable 'l24' could be marked 'constexpr'. |
23-
| test.cpp:263:7:263:9 | l25 | Variable 'l25' could be marked 'constexpr'. |
11+
| test.cpp:65:7:65:8 | x2 | Variable 'x2' could be marked 'constexpr'. |
12+
| test.cpp:66:13:66:14 | x3 | Variable 'x3' could be marked 'constexpr'. |
13+
| test.cpp:76:7:76:8 | m1 | Variable 'm1' could be marked 'constexpr' and static. |
14+
| test.cpp:91:7:91:8 | l1 | Variable 'l1' could be marked 'constexpr'. |
15+
| test.cpp:105:7:105:8 | l6 | Variable 'l6' could be marked 'constexpr'. |
16+
| test.cpp:107:7:107:8 | l8 | Variable 'l8' could be marked 'constexpr'. |
17+
| test.cpp:110:7:110:9 | l10 | Variable 'l10' could be marked 'constexpr'. |
18+
| test.cpp:113:7:113:9 | l12 | Variable 'l12' could be marked 'constexpr'. |
19+
| test.cpp:118:7:118:9 | l15 | Variable 'l15' could be marked 'constexpr'. |
20+
| test.cpp:120:7:120:9 | l16 | Variable 'l16' could be marked 'constexpr'. |
21+
| test.cpp:121:7:121:9 | l17 | Variable 'l17' could be marked 'constexpr'. |
22+
| test.cpp:127:7:127:9 | l21 | Variable 'l21' could be marked 'constexpr'. |
23+
| test.cpp:132:7:132:9 | l24 | Variable 'l24' could be marked 'constexpr'. |
24+
| test.cpp:133:7:133:9 | l25 | Variable 'l25' could be marked 'constexpr'. |

cpp/autosar/test/rules/A7-1-2/test.cpp

+7-137
Original file line numberDiff line numberDiff line change
@@ -56,71 +56,17 @@ class MemberConstExpr {
5656
int m3 = 0; // COMPLIANT - can be set by constructor
5757
};
5858

59-
int h1(int x, int y) { // NON_COMPLIANT
60-
return x + y;
61-
}
62-
63-
constexpr int h1_correct(int x, int y) { // COMPLIANT
64-
return x + y;
65-
}
66-
67-
int h2(int x) { return h1(x, 1) + 1; } // NON_COMPLIANT
68-
constexpr int h2_correct(int x) { return h1_correct(x, 1) + 1; } // COMPLIANT
69-
70-
int h3(int x) { // COMPLIANT - uses goto, so can't be constexpr
71-
if (x) {
72-
goto l1;
73-
} else {
74-
return 10;
75-
}
76-
l1:
77-
return 1;
78-
}
79-
80-
int h4(int x) { // COMPLIANT - uses try, so can't be constexpr
81-
try {
82-
return 1;
83-
} catch (...) {
84-
}
85-
}
86-
87-
int h5(int x) { // COMPLIANT - declares non literal local var
88-
NonLiteralClass nlc;
89-
}
90-
91-
int h6(int x) { // COMPLIANT - declares static variable
92-
static int i = x;
93-
return x;
94-
}
95-
96-
int h7(int x) { // COMPLIANT - declares no init variable
97-
int i;
98-
}
59+
int h1(int x, int y) { return x + y; }
9960

100-
int h8(int x) { // NON_COMPLIANT - could be constexpr
101-
int i = x;
102-
return i;
103-
}
61+
constexpr int h1_const(int x, int y) { return x + y; }
10462

105-
constexpr int h8_correct(int x) { // COMPLIANT
106-
int i = x;
107-
return i;
63+
int h2() {
64+
int x1 = h1(1, 1); // COMPLIANT
65+
int x2 = h1_const(1, 1); // NON_COMPLIANT
66+
const int x3 = h1_const(1, 1); // NON_COMPLIANT
67+
constexpr int x4 = h1_const(1, 1); // COMPLIANT
10868
}
10969

110-
int h9(int x) { // COMPLIANT - declares thread local variable
111-
thread_local int i = x;
112-
return x;
113-
}
114-
115-
class ConstexprFunctionClass {
116-
public:
117-
int mf1(int x) { return m1 + x; } // NON_COMPLIANT
118-
constexpr int mf1_correct(int x) { return m1 + x; } // COMPLIANT
119-
120-
private:
121-
int m1;
122-
};
123-
12470
class MissingConstexprClass {
12571
public:
12672
MissingConstexprClass() = default; // NON_COMPLIANT
@@ -130,82 +76,6 @@ class MissingConstexprClass {
13076
int m1 = 0; // NON_COMPLIANT
13177
};
13278

133-
class VirtualBaseClass {};
134-
135-
class DerivedClass : public virtual VirtualBaseClass {
136-
public:
137-
DerivedClass() = default; // COMPLIANT
138-
DerivedClass(int i) = delete; // COMPLIANT
139-
DerivedClass(int i, LiteralClass lc) {} // COMPLIANT
140-
private:
141-
int m1 = 0; // NON_COMPLIANT
142-
};
143-
144-
class NotAllMembersInitializedClass {
145-
public:
146-
NotAllMembersInitializedClass() = default; // COMPLIANT
147-
NotAllMembersInitializedClass(int i) = delete; // COMPLIANT
148-
NotAllMembersInitializedClass(int i, LiteralClass lc) {} // COMPLIANT
149-
private:
150-
int m1;
151-
};
152-
153-
class NonLiteralParamsClass {
154-
public:
155-
NonLiteralParamsClass(int i, NonLiteralClass lc) {} // COMPLIANT
156-
};
157-
158-
// Variant members are always initialized, so this can be marked constexpr
159-
class VariantMemberInitialized {
160-
public:
161-
VariantMemberInitialized() = default; // NON_COMPLIANT
162-
VariantMemberInitialized(int i) = delete; // NON_COMPLIANT
163-
VariantMemberInitialized(int i, LiteralClass lc) {} // NON_COMPLIANT
164-
private:
165-
union {
166-
int i = 0;
167-
short s;
168-
};
169-
};
170-
171-
class VariantMemberInitConstexpr {
172-
public:
173-
constexpr VariantMemberInitConstexpr() = default; // COMPLIANT
174-
constexpr VariantMemberInitConstexpr(int i) = delete; // COMPLIANT
175-
constexpr VariantMemberInitConstexpr(int i, LiteralClass lc) {} // COMPLIANT
176-
private:
177-
union {
178-
int i = 0;
179-
short s;
180-
};
181-
};
182-
183-
// Variant members are not initialized at declaration, so we can only mark the
184-
// constructors as constexpr if we explicitly initialize the variant member
185-
class VariantMemberNotInit {
186-
public:
187-
VariantMemberNotInit() = default; // COMPLIANT
188-
VariantMemberNotInit(int pi) = delete; // COMPLIANT
189-
VariantMemberNotInit(int pi, LiteralClass lc) {} // COMPLIANT
190-
VariantMemberNotInit(LiteralClass lc, int pi) : i(pi) {} // NON_COMPLIANT
191-
constexpr VariantMemberNotInit(LiteralClass lc, short pi) // COMPLIANT
192-
: i(pi) {}
193-
194-
private:
195-
union {
196-
int i;
197-
short s;
198-
};
199-
};
200-
201-
class ExcludedCases {
202-
public:
203-
~ExcludedCases() {} // COMPLIANT
204-
205-
void operator=(ExcludedCases &) {} // COMPLIANT
206-
void operator=(ExcludedCases &&) {} // COMPLIANT
207-
};
208-
20979
extern int random();
21080
constexpr int add(int x, int y) { return x + y; }
21181
// Example with compile time constant literal value as default argument

0 commit comments

Comments
 (0)