Suppressing one warning from -Weffc++

1.1k views Asked by At

Adding the -Weffc++ flag already caught 2 real bugs in my code, so I'd like to leave it in. Unfortunately it leads to the following:

record-set.h:60:7: warning: ‘class RecordSet’ has pointer data members [-Weffc++]
record-set.h:60:7: warning:   but does not override ‘RecordSet(const RecordSet&)’ [-Weffc++]
record-set.h:60:7: warning:   or ‘operator=(const RecordSet&)’ [-Weffc++]

The warning is accurate. A RecordSet is basically a subset of a std::vector< Record > matching a rule. (I actually point to a data structure containing that, and a definition of what fields a Record has.) It has pointer data members because when I update a record, I need to update the original.

https://github.com/c42f/tinyformat/pull/4 offers the idea of just declaring the necessary functions to be private, then not use them. Unfortunately I do things like return a RecordSet from a function, so I need the copy constructor to actually exist with the default behavior.

The ideal would be to find some sort of inline comment that would tell gcc that yes, really, I want an exception here but please warn me about anything else that goes wrong.

Next best would be to write my own versions of those two functions that does exactly what the default does. I'm unfortunately not confident in my ability to get those exactly right. Can someone point me to a canonical example?

Easiest, of course, is to turn this flag off. But given that it caught real bugs for me, I would like to avoid that.

0

There are 0 answers