0

I am getting a warning when compiling with gcc11 c++20. Can you help me solve it?

ERROR:

DragonSoul.cpp:516:18: warning: the compiler can assume that the address of 'aItemPoses' will never be NULL [-Waddress]

DragonSoul.cpp:516:9: warning: 'nonnull' argument 'aItemPoses' compared to NULL [-Wnonnull-compare]

CODE:

bool DSManager::DoRefineGrade(LPCHARACTER ch, TItemPos (&aItemPoses)[DRAGON_SOUL_REFINE_GRID_SIZE])
{
    if (NULL == ch)
        return false;
    
    if (NULL == aItemPoses)
    {
        return false;
    }
    ...
wohlstad
  • 12,661
  • 10
  • 26
  • 39
Nebi S.
  • 1
  • 1
  • 4
    The warning speaks for itself? You can't have null references. – HolyBlackCat Feb 17 '22 at 20:20
  • 1
    as above said, your check at line is nonsensical because it can never pass. The compiler is telling you that you don't understand the language. The compiler will literally remove that test and if you did create a null reference you will be very confused why your return false; didn't happen. If you added that check because of a problem you found, you need to fix the problem at its source - where you created the reference. – xaxxon Feb 17 '22 at 20:25
  • How do I edit the code to solve this error? – Nebi S. Feb 17 '22 at 20:41
  • 1
    Remove the `if (NULL == aItemPoses) { ... }` part from the code. – Eljay Feb 17 '22 at 21:35

0 Answers0