https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81250
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> --- In simple cases a ctor only writes into the memory allocated for an object and doesn't read any of it (after it's been written) I think it should be possible to detect that none of the object's members is read before its dtor is invoked. This is difficult today because, in general, GCC doesn't know whether any arbitrary function that takes its argument(s) by reference (or pointer) reads or just writes them. To tell which it is, GCC needs an annotation (e.g., something like attributes "in" and "out", or "write-only" and "read-only") to mark such arguments. With such an annotation, if all functions called on an object between its ctor and dtor were marked write-only, GCC could issue a warning that the object was not used. It would be up to the programmer to annotate each function (or member function). I have been testing a solution along these lines but it's not far enough along for me to say for certain that it will work for std::string. Even if it does, the -Wsystem-headers problem will need to be solved for warnings from standard headers to be issued.