File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1118,6 +1118,9 @@ void CheckClass::operatorEq()
11181118
11191119 for (func = scope->functionList .begin (); func != scope->functionList .end (); ++func) {
11201120 if (func->type == Function::eOperatorEqual && func->access != Private) {
1121+ // skip if there's =delete in the declaration - cannot be called anyway
1122+ if (func->tokenDef && func->tokenDef ->next () && Token::Match (func->tokenDef ->next ()->link (), " ) const| = delete" ))
1123+ continue ;
11211124 // use definition for check so we don't have to deal with qualification
11221125 if (!(Token::Match (func->retDef , " %type% &" ) && func->retDef ->str () == scope->className )) {
11231126 // make sure we really have a copy assignment operator
Original file line number Diff line number Diff line change @@ -556,13 +556,28 @@ class TestClass : public TestFixture {
556556 " };" );
557557 ASSERT_EQUALS (" [test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n " , errout.str ());
558558
559+ checkOpertorEq (" class A\n "
560+ " {\n "
561+ " public:\n "
562+ " void goo() {}"
563+ " void operator=(const A&)=delete;\n "
564+ " };" );
565+ ASSERT_EQUALS (" " , errout.str ());
566+
559567 checkOpertorEq (" class A\n "
560568 " {\n "
561569 " private:\n "
562570 " void operator=(const A&);\n "
563571 " };" );
564572 ASSERT_EQUALS (" " , errout.str ());
565573
574+ checkOpertorEq (" class A\n "
575+ " {\n "
576+ " private:\n "
577+ " void operator=(const A&)=delete;\n "
578+ " };" );
579+ ASSERT_EQUALS (" " , errout.str ());
580+
566581 checkOpertorEq (" class A\n "
567582 " {\n "
568583 " void operator=(const A&);\n "
@@ -596,6 +611,12 @@ class TestClass : public TestFixture {
596611 " void operator=(const A&);\n "
597612 " };" );
598613 ASSERT_EQUALS (" [test.cpp:3]: (style) 'A::operator=' should return 'A &'.\n " , errout.str ());
614+
615+ checkOpertorEq (" struct A\n "
616+ " {\n "
617+ " void operator=(const A&)=delete;\n "
618+ " };" );
619+ ASSERT_EQUALS (" " , errout.str ());
599620 }
600621
601622 void operatorEq2 () {
You can’t perform that action at this time.
0 commit comments