Skip to content

Commit 2db65fe

Browse files
committed
Add unit tests for constexpr constructors
This also adds unit tests for inline+explicit constructors being okay, with and without constexpr.
1 parent cf4071c commit 2db65fe

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

cpplint/cpplint_unittest.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,80 @@ class Foo {
13161316
};""",
13171317
'Single-parameter constructors should be marked explicit.'
13181318
' [runtime/explicit] [5]')
1319+
# missing explicit for constexpr constructors is bad as well
1320+
self.TestMultiLineLint(
1321+
"""
1322+
class Foo {
1323+
constexpr Foo(int f);
1324+
};""",
1325+
'Single-parameter constructors should be marked explicit.'
1326+
' [runtime/explicit] [5]')
1327+
# missing explicit for constexpr+inline constructors is bad as well
1328+
self.TestMultiLineLint(
1329+
"""
1330+
class Foo {
1331+
constexpr inline Foo(int f);
1332+
};""",
1333+
'Single-parameter constructors should be marked explicit.'
1334+
' [runtime/explicit] [5]')
1335+
self.TestMultiLineLint(
1336+
"""
1337+
class Foo {
1338+
inline constexpr Foo(int f);
1339+
};""",
1340+
'Single-parameter constructors should be marked explicit.'
1341+
' [runtime/explicit] [5]')
1342+
# explicit with inline is accepted
1343+
self.TestMultiLineLint(
1344+
"""
1345+
class Foo {
1346+
inline explicit Foo(int f);
1347+
};""",
1348+
'')
1349+
self.TestMultiLineLint(
1350+
"""
1351+
class Foo {
1352+
explicit inline Foo(int f);
1353+
};""",
1354+
'')
1355+
# explicit with constexpr is accepted
1356+
self.TestMultiLineLint(
1357+
"""
1358+
class Foo {
1359+
constexpr explicit Foo(int f);
1360+
};""",
1361+
'')
1362+
self.TestMultiLineLint(
1363+
"""
1364+
class Foo {
1365+
explicit constexpr Foo(int f);
1366+
};""",
1367+
'')
1368+
# explicit with constexpr+inline is accepted
1369+
self.TestMultiLineLint(
1370+
"""
1371+
class Foo {
1372+
inline constexpr explicit Foo(int f);
1373+
};""",
1374+
'')
1375+
self.TestMultiLineLint(
1376+
"""
1377+
class Foo {
1378+
explicit inline constexpr Foo(int f);
1379+
};""",
1380+
'')
1381+
self.TestMultiLineLint(
1382+
"""
1383+
class Foo {
1384+
constexpr inline explicit Foo(int f);
1385+
};""",
1386+
'')
1387+
self.TestMultiLineLint(
1388+
"""
1389+
class Foo {
1390+
explicit constexpr inline Foo(int f);
1391+
};""",
1392+
'')
13191393
# structs are caught as well.
13201394
self.TestMultiLineLint(
13211395
"""

0 commit comments

Comments
 (0)