File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -319,6 +319,11 @@ void CheckClass::constructors()
319319 }
320320}
321321
322+ static bool isPermissibleConversion (const std::string& type)
323+ {
324+ return type == " std::initializer_list" || type == " std::nullptr_t" ;
325+ }
326+
322327void CheckClass::checkExplicitConstructors ()
323328{
324329 if (!mSettings ->severity .isEnabled (Severity::style) && !mSettings ->isPremiumEnabled (" noExplicitConstructor" ))
@@ -357,7 +362,7 @@ void CheckClass::checkExplicitConstructors()
357362 func.type != FunctionType::eCopyConstructor &&
358363 func.type != FunctionType::eMoveConstructor &&
359364 !(func.templateDef && Token::simpleMatch (func.argumentList .front ().typeEndToken (), " ..." )) &&
360- func.argumentList .front ().getTypeName () != " std::initializer_list " ) {
365+ ! isPermissibleConversion ( func.argumentList .front ().getTypeName ()) ) {
361366 noExplicitConstructorError (func.tokenDef , scope->className , scope->type == ScopeType::eStruct);
362367 }
363368 }
Original file line number Diff line number Diff line change @@ -503,6 +503,14 @@ class TestClass : public TestFixture {
503503 ASSERT_EQUALS (" [test.cpp:3:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n "
504504 " [test.cpp:4:5]: (style) Class 'Color' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]\n " ,
505505 errout_str ());
506+
507+ checkExplicitConstructors (" template <typename T>\n " // #13878
508+ " struct S {\n "
509+ " S(std::nullptr_t) {}\n "
510+ " explicit S(T* p) : m(p) {}\n "
511+ " T* m{};\n "
512+ " };\n " );
513+ ASSERT_EQUALS (" " , errout_str ());
506514 }
507515
508516#define checkDuplInheritedMembers (...) checkDuplInheritedMembers_( __FILE__, __LINE__, __VA_ARGS__)
You can’t perform that action at this time.
0 commit comments