[cfe-commits] r165769 - /cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h

Sean Silva silvas at purdue.edu
Thu Oct 11 21:23:03 PDT 2012


Thanks both of you for your help. It's good to have experts around :)

I'll get this rigged up.

-- Sean Silva

On Thu, Oct 11, 2012 at 10:33 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Thu, Oct 11, 2012 at 7:10 PM, Eli Friedman <eli.friedman at gmail.com>
> wrote:
>>
>> On Thu, Oct 11, 2012 at 4:31 PM, Sean Silva <silvas at purdue.edu> wrote:
>> > Author: silvas
>> > Date: Thu Oct 11 18:31:18 2012
>> > New Revision: 165769
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=165769&view=rev
>> > Log:
>> > Add missing classof().
>> >
>> > Somewhat troublingly, without this implemented, the check inside
>> > isa_impl<> would silently use the parent's `classof()` when determining
>> > whether it was okay to downcast from the parent to the child!
>> >
>> > Bug analysis:
>> >
>> > A build failure after removing the parent's `classof()` initially
>> > alerted me to the bug, after which a little bit of thinking and reading
>> > of the code identified the root cause.
>> >
>> > The compiler could be made to prevent this bug from happening if there
>> > were a way to ensure that in the code
>> >
>> >     template <typename To, typename From, typename Enabler = void>
>> >     struct isa_impl {
>> >       static inline bool doit(const From &Val) {
>> >         return To::classof(&Val);
>> >       }
>> >     };
>> >
>> > that `To::classof` is actually inside the class `To`, and not in a base
>> > class. I am not aware of a way to check this in C++. If there is a means
>> > to perform that check, please bring it up on the list and this will be
>> > fixed.
>>
>> Stupid attempt:
>>
>> struct A { void f(); };
>> struct B : A {
>> #ifdef B_HAS_F
>>   void f();
>> #endif
>> };
>> decltype(&B::f) x;
>> extern void (B::*x)(); // error unless B_HAS_F
>>
>> Unfortunately, not a complete solution, because you don't know the
>> precise signature of the classof you're looking for.
>
>
> I was pondering that (and you can solve the immediate problem pretty
> straightforwardly), but I don't think it can be made to work if B::f is
> overloaded.



More information about the cfe-commits mailing list