tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: EV_SET() better C++ compat with alternative implementations



On 11.08.2019 19:17, Christos Zoulas wrote:
> Did you use -Wold-style-cast? We've come full circle now, and what we have seems
> to be more complicated than what we had before and I am not sure what was the
> problem in the first place... Can we just step back and understand what is the problem
> we are trying to solve with all this complexity?
> 
> christos
> 

It's all clean for -Wold-style-cast.

$ cat test.cpp


#include <sys/types.h>
#include <sys/event.h>

#include <cinttypes>
#include <cstdio>

int
main(int argc, char **argv)
{
       struct kevent kv;

       EV_SET(&kv, 0, 0, 0, 0, 0, 0);

        printf("%" PRIxPTR "\n", kv.udata);

       EV_SET(&kv, 0, 0, 0, 0, 0, NULL);
        printf("%" PRIxPTR "\n", kv.udata);

#if __cplusplus >= 201103L
       EV_SET(&kv, 0, 0, 0, 0, 0, nullptr);
        printf("%" PRIxPTR "\n", kv.udata);
#endif
       EV_SET(&kv, 0, 0, 0, 0, 0, 0L);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 0LL);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 0U);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 0UL);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 0ULL);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, static_cast<intptr_t>(0));
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, static_cast<uintptr_t>(0));
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 'a');
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0,  3.5);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0,  "aa");
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0,  static_cast<short>(0));
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0,  static_cast<char>(0));
        printf("%" PRIxPTR "\n", kv.udata);

       EV_SET(&kv, 0, 0, 0, 0, 0, 1);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, NULL);
        printf("%" PRIxPTR "\n", kv.udata);
#if __cplusplus >= 201103L
       EV_SET(&kv, 0, 0, 0, 0, 0, nullptr);
        printf("%" PRIxPTR "\n", kv.udata);
#endif
       EV_SET(&kv, 0, 0, 0, 0, 0, 1L);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 1LL);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 1U);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 1UL);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 1ULL);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, static_cast<intptr_t>(0));
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, static_cast<uintptr_t>(0));
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0, 'a');
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0,  3.5);
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0,  "aa");
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0,  static_cast<short>(0));
        printf("%" PRIxPTR "\n", kv.udata);
       EV_SET(&kv, 0, 0, 0, 0, 0,  static_cast<char>(0));
        printf("%" PRIxPTR "\n", kv.udata);

       return 0;
}

$ clang++ -std=c++11  -Wall  -Wold-style-cast -Weverything -pedantic
test.cpp
test.cpp:20:35: warning: 'nullptr' is incompatible with C++98
[-Wc++98-compat]
       EV_SET(&kv, 0, 0, 0, 0, 0, nullptr);
                                  ^
test.cpp:25:35: warning: 'long long' is incompatible with C++98
[-Wc++98-compat-pedantic]
       EV_SET(&kv, 0, 0, 0, 0, 0, 0LL);
                                  ^
test.cpp:31:35: warning: 'long long' is incompatible with C++98
[-Wc++98-compat-pedantic]
       EV_SET(&kv, 0, 0, 0, 0, 0, 0ULL);
                                  ^
test.cpp:53:35: warning: 'nullptr' is incompatible with C++98
[-Wc++98-compat]
       EV_SET(&kv, 0, 0, 0, 0, 0, nullptr);
                                  ^
test.cpp:58:35: warning: 'long long' is incompatible with C++98
[-Wc++98-compat-pedantic]
       EV_SET(&kv, 0, 0, 0, 0, 0, 1LL);
                                  ^
test.cpp:64:35: warning: 'long long' is incompatible with C++98
[-Wc++98-compat-pedantic]
       EV_SET(&kv, 0, 0, 0, 0, 0, 1ULL);
                                  ^
test.cpp:8:10: warning: unused parameter 'argc' [-Wunused-parameter]
main(int argc, char **argv)
         ^
test.cpp:8:23: warning: unused parameter 'argv' [-Wunused-parameter]
main(int argc, char **argv)
                      ^
8 warnings generated.

$ g++ -std=c++11  -Wall  -Wold-style-cast -pedantic test.cpp

$

Attachment: signature.asc
Description: OpenPGP digital signature



Home | Main Index | Thread Index | Old Index