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:
Nicodemes 2019-04-23 10:46:22 +02:00 committed by Daniel Marjamäki
parent 315a093e18
commit 272760f9ca
2 changed files with 6 additions and 1 deletions

View File

@ -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);

View File

@ -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[]) {