From 2db65fed51cf28fb6c888b0661acffb97c50dcac Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 2 Mar 2017 13:19:58 -0500 Subject: [PATCH] Add unit tests for constexpr constructors This also adds unit tests for inline+explicit constructors being okay, with and without constexpr. --- cpplint/cpplint_unittest.py | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index b8b8319..3086269 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -1316,6 +1316,80 @@ class CpplintTest(CpplintTestBase): };""", 'Single-parameter constructors should be marked explicit.' ' [runtime/explicit] [5]') + # missing explicit for constexpr constructors is bad as well + self.TestMultiLineLint( + """ + class Foo { + constexpr Foo(int f); + };""", + 'Single-parameter constructors should be marked explicit.' + ' [runtime/explicit] [5]') + # missing explicit for constexpr+inline constructors is bad as well + self.TestMultiLineLint( + """ + class Foo { + constexpr inline Foo(int f); + };""", + 'Single-parameter constructors should be marked explicit.' + ' [runtime/explicit] [5]') + self.TestMultiLineLint( + """ + class Foo { + inline constexpr Foo(int f); + };""", + 'Single-parameter constructors should be marked explicit.' + ' [runtime/explicit] [5]') + # explicit with inline is accepted + self.TestMultiLineLint( + """ + class Foo { + inline explicit Foo(int f); + };""", + '') + self.TestMultiLineLint( + """ + class Foo { + explicit inline Foo(int f); + };""", + '') + # explicit with constexpr is accepted + self.TestMultiLineLint( + """ + class Foo { + constexpr explicit Foo(int f); + };""", + '') + self.TestMultiLineLint( + """ + class Foo { + explicit constexpr Foo(int f); + };""", + '') + # explicit with constexpr+inline is accepted + self.TestMultiLineLint( + """ + class Foo { + inline constexpr explicit Foo(int f); + };""", + '') + self.TestMultiLineLint( + """ + class Foo { + explicit inline constexpr Foo(int f); + };""", + '') + self.TestMultiLineLint( + """ + class Foo { + constexpr inline explicit Foo(int f); + };""", + '') + self.TestMultiLineLint( + """ + class Foo { + explicit constexpr inline Foo(int f); + };""", + '') # structs are caught as well. self.TestMultiLineLint( """