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

Joshua Cranmer pidgeot18 at gmail.com
Mon Aug 27 07:38:46 PDT 2012


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




More information about the cfe-dev mailing list