Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6a6fc7f

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 parents2acc92a +07cea2a commit6a6fc7f

File tree

8 files changed

+23
-355
lines changed

8 files changed

+23
-355
lines changed
Lines changed: 2 additions & 0 deletions
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‎

Lines changed: 0 additions & 160 deletions
This file was deleted.

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

Lines changed: 14 additions & 13 deletions
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‎

Lines changed: 7 additions & 137 deletions
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-
inth1(int x,int y) {// NON_COMPLIANT
60-
return x + y;
61-
}
62-
63-
constexprinth1_correct(int x,int y) {// COMPLIANT
64-
return x + y;
65-
}
66-
67-
inth2(int x) {returnh1(x,1) +1; }// NON_COMPLIANT
68-
constexprinth2_correct(int x) {returnh1_correct(x,1) +1; }// COMPLIANT
69-
70-
inth3(int x) {// COMPLIANT - uses goto, so can't be constexpr
71-
if (x) {
72-
goto l1;
73-
}else {
74-
return10;
75-
}
76-
l1:
77-
return1;
78-
}
79-
80-
inth4(int x) {// COMPLIANT - uses try, so can't be constexpr
81-
try {
82-
return1;
83-
}catch (...) {
84-
}
85-
}
86-
87-
inth5(int x) {// COMPLIANT - declares non literal local var
88-
NonLiteralClass nlc;
89-
}
90-
91-
inth6(int x) {// COMPLIANT - declares static variable
92-
staticint i = x;
93-
return x;
94-
}
95-
96-
inth7(int x) {// COMPLIANT - declares no init variable
97-
int i;
98-
}
59+
inth1(int x,int y) {return x + y; }
9960

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

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

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

133-
classVirtualBaseClass {};
134-
135-
classDerivedClass :publicvirtual 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-
classNotAllMembersInitializedClass {
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-
classNonLiteralParamsClass {
154-
public:
155-
NonLiteralParamsClass(int i, NonLiteralClass lc) {}// COMPLIANT
156-
};
157-
158-
// Variant members are always initialized, so this can be marked constexpr
159-
classVariantMemberInitialized {
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-
classVariantMemberInitConstexpr {
172-
public:
173-
constexprVariantMemberInitConstexpr() = default;// COMPLIANT
174-
constexprVariantMemberInitConstexpr(int i) = delete;// COMPLIANT
175-
constexprVariantMemberInitConstexpr(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-
classVariantMemberNotInit {
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-
constexprVariantMemberNotInit(LiteralClass lc,short pi)// COMPLIANT
192-
: i(pi) {}
193-
194-
private:
195-
union {
196-
int i;
197-
short s;
198-
};
199-
};
200-
201-
classExcludedCases {
202-
public:
203-
~ExcludedCases() {}// COMPLIANT
204-
205-
voidoperator=(ExcludedCases &) {}// COMPLIANT
206-
voidoperator=(ExcludedCases &&) {}// COMPLIANT
207-
};
208-
20979
externintrandom();
21080
constexprintadd(int x,int y) {return x + y; }
21181
// Example with compile time constant literal value as default argument

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp