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()
1118
1118
1119
1119
for (func = scope->functionList .begin (); func != scope->functionList .end (); ++func) {
1120
1120
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 ;
1121
1124
// use definition for check so we don't have to deal with qualification
1122
1125
if (!(Token::Match (func->retDef , " %type% &" ) && func->retDef ->str () == scope->className )) {
1123
1126
// 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 {
556
556
" };" );
557
557
ASSERT_EQUALS (" [test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n " , errout.str ());
558
558
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
+
559
567
checkOpertorEq (" class A\n "
560
568
" {\n "
561
569
" private:\n "
562
570
" void operator=(const A&);\n "
563
571
" };" );
564
572
ASSERT_EQUALS (" " , errout.str ());
565
573
574
+ checkOpertorEq (" class A\n "
575
+ " {\n "
576
+ " private:\n "
577
+ " void operator=(const A&)=delete;\n "
578
+ " };" );
579
+ ASSERT_EQUALS (" " , errout.str ());
580
+
566
581
checkOpertorEq (" class A\n "
567
582
" {\n "
568
583
" void operator=(const A&);\n "
@@ -596,6 +611,12 @@ class TestClass : public TestFixture {
596
611
" void operator=(const A&);\n "
597
612
" };" );
598
613
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 ());
599
620
}
600
621
601
622
void operatorEq2 () {
You can’t perform that action at this time.
0 commit comments