Fix explicit constructor with default arguments check bug
Before this fix, the code: ``` class A { A(int, int x=3){ x; } }; ``` Was considered OK. But explicit keyword is still needed I'm still new to open-source contributions, so I will gladly take advice.
This commit is contained in:
parent
315a093e18
commit
272760f9ca
|
@ -273,7 +273,7 @@ void CheckClass::checkExplicitConstructors()
|
|||
continue;
|
||||
|
||||
if (!func.isExplicit() &&
|
||||
func.argCount() == 1 &&
|
||||
func.minArgCount() == 1 &&
|
||||
func.type != Function::eCopyConstructor &&
|
||||
func.type != Function::eMoveConstructor) {
|
||||
noExplicitConstructorError(func.tokenDef, scope->className, scope->type == Scope::eStruct);
|
||||
|
|
|
@ -430,6 +430,11 @@ private:
|
|||
" B(const B&) {}\n"
|
||||
"};");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkExplicitConstructors("struct A{"
|
||||
" A(int, int y=2) {}"
|
||||
"};");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (style) Struct 'A' has a constructor with 1 argument that is not explicit.\n", errout.str());
|
||||
}
|
||||
|
||||
void checkDuplInheritedMembers(const char code[]) {
|
||||
|
|
Loading…
Reference in New Issue