[cfe-dev] Warning about undefined methods/static attributes ?

Matthieu Monrocq matthieu.monrocq at gmail.com
Mon Aug 27 10:08:49 PDT 2012


On Mon, Aug 27, 2012 at 4:38 PM, Joshua Cranmer <pidgeot18 at gmail.com> wrote:

> On 8/27/2012 6:48 AM, Matthieu Monrocq wrote:
>
>> Hello,
>>
>> I just had the case today (yet another time) of a newcomer to the C++
>> language getting caught by the rather ominous message, when launching his
>> binary: "undefined symbol _ZN....." because he had forgotten to implement
>> one of the methods of his class.
>>
>> I was wondering whether there would be interest in a warning catching
>> this, and if indeed people had ideas about implementing such a warning. I
>> believe there are specific linker flags designed to catch this a bit
>> earlier on, but even a warning at linking stage is too lately produced for
>> a "beautiful" diagnosis.
>>
>> My idea was that once the AST has been completely produced for a given
>> translation unit, one could check the methods/static attributes defined in
>> the *one* file passed to the compiler (probably ending in .cpp) and check
>> that all the classes involved are now complete (in terms of definition).
>>
>> This is definitely a heuristic, and may not make sense as a default
>> warning if some projects have the habit of splitting their class
>> implementation into several files, but I have never encountered such a case
>> in practice.
>>
>
> It also doesn't make sense if you want to not provide definitions of some
> methods (a poor man's = delete for people who need to support pre-C++11).
>
> On Linux at least, -Wl,-z,defs will cause the linker to complain if you
> omit a method.
>
> --
> Joshua Cranmer
> News submodule owner
> DXR coauthor
>
>
> ______________________________**_________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/**mailman/listinfo/cfe-dev<http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev>
>


In no particular order:

> implementations split across files:

I think that at one point there had been a proposal for a group of warnings
dedicated to beginners, I would expect such a missing-definition warning to
be part of this group and not be on by default.

More seasoned developers are generally well aware of the issue and can read
through mangled symbols (at least the first few words, to get the
namespace(s), class/method names) and otherwise know to use c++filt (or
equivalent) to get a readable one.

> linker flags:

I am aware that the linker may check this, as I said. However the diagnosis
is not particularly pretty (in general), notably it is not pointing to the
declaration of the method and the output need be run through c++filt to
demangle the symbol (in C++).

> poor's man delete:

Indeed, this is a concern. It's a widely used technic pre-C++11. Such
methods are generally private, and most often than not only consist of the
copy constructor and assignment operator (I have used it only a few times
to "remove" other operations), so maybe blacklisting those two (when
declared private) would be sufficient to bring the noise level down to a
reasonable treshold ?

I had not thought about this latter point and indeed it seems to put the
idea of the warning in jeopardy. If nobody express any interest in this or
has any very good idea on this latter point, I'll forget about it ;)

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120827/84f614ca/attachment.html>


More information about the cfe-dev mailing list