[cfe-commits] [PATCH] C++11 nullptr-convert standalone tool

Eli Friedman eli.friedman at gmail.com
Wed Nov 28 13:07:59 PST 2012


clang generally doesn't try to partially analyze expressions of
dependent type, so we don't do any analysis on e.g. "T* x = 0;".  To
put it another way, clang doesn't bother to distinguish between "T* x
= 0" and "T x = 0;".  The general case is rather complicated, and
there isn't usually any benefit.

-Eli

On Wed, Nov 28, 2012 at 10:22 AM, Edwin Vane <edwin.vane at intel.com> wrote:
>
>   So I tried looking for ImplicitCastExpr where the CastKind was CK_NullToPointer or CK_NullToMemberPointer. This does handle most of the cases with a single simple matcher. However, there are two test of my test cases failing:
>
>   int *p;
>   p = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));
>   // CHECK: p = nullptr;
>
>   template <typename T>
>   struct Bar {
>     Bar(T *p = NULL) : m_p(p) {
>     // CHECK: Bar(T *p = nullptr) : m_p(p) {
>
>   In the first case, the NULL gets replaced but the explicit casts do not. This is expected given the simple matcher. I expect the fix here is to match all cast expressions and use Expr::isNullPointerConstant().
>
>   The second case doesn't work because there's no implicit cast involved. Looking at the AST dump I see this:
>
>   template <typename T = int> struct Bar {
>       struct Bar;
>       Bar(int *p) : m_p((ImplicitCastExpr 0x428fad8 <basic.cpp:67:26> 'int *' <LValueToRValue>
>     (DeclRefExpr 0x428fa80 <col:26> 'int *' lvalue ParmVar 0x428e880 'p' 'int *'))
>
>   and
>
>   template <typename T> struct Bar {
>       struct Bar;
>       Bar<T>(T *p = (IntegerLiteral 0x428c550 <basic.cpp:7:14> 'int' 0)
>   ) : m_p((DeclRefExpr 0x428c598 <basic.cpp:67:26> 'T *' lvalue ParmVar 0x4284e00 'p' 'T *')
>
>   It seems to me that in this template case, there should be an implicit cast since we know T* will be some sort of pointer type. Is that a bug or something I just have to live with?
>
> http://llvm-reviews.chandlerc.com/D136
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list