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

Sean Silva silvas at purdue.edu
Thu Oct 11 19:31:48 PDT 2012


> 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.

Thanks! (there's a typedef needed before the decltype, right?)

Could this be made workable if we know that the classof() has the signature
    static bool classof(const T *);
where T is strictly is_base_of the enclosing class?

Also, is it possible to do without the decltype?

-- Sean Silva

On Thu, Oct 11, 2012 at 10: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.
>
> -Eli



More information about the cfe-commits mailing list