Menu

new "condition is always true/false" FPs

Martin
2022-08-30
2022-08-31
  • Martin

    Martin - 2022-08-30

    Hi,

    with
    98b2fd8151897274bfacf5cf151068536c9be3c5
    there are a number of new FPs:

    return static_cast<pa_usec_t>(-1);
    (style) Condition 'static_cast<pa_usec_t>(-1)' is always true
    
    return (HttpRequestType)0;
    (style) Condition '(HttpRequestType)0' is always false
    
    return std::shared_ptr<SoftwareUpdateObject>(nullptr);
    (style) Condition 'std::shared_ptr<SoftwareUpdateObject>(nullptr)' is always false
    
    return std::unique_ptr<Value>(nullptr);
    (style) Condition 'std::unique_ptr<Value>(nullptr)' is always false
    
    return reinterpret_cast<unsigned char const*>(p);
    (style) Condition 'reinterpret_cast<unsigned char const*>(p)' is always false
    
    return (char *) -1;
    (style) Condition '(char*)-1' is always true
    

    Could you please check?

    Thanks,
    Martin

     
  • CHR

    CHR - 2022-08-30
     
  • Martin

    Martin - 2022-08-30

    Regarding that pull request, why is

    "[test.cpp:7]: (style) Condition '(int)0' is always false\n"
    

    (line 4333 in testcondítion.cpp)
    a correct finding? There's no condition in

    return (int)0;
    

    Same for

    return static_cast<int>(1)
    
     

    Last edit: Martin 2022-08-30
  • CHR

    CHR - 2022-08-30

    Because those statements are equivalent to return false/true;respectively (if the return type is bool)?

     
  • Martin

    Martin - 2022-08-30

    But false/true aren't conditions, but boolean values? What's wrong with "return true"?

     
  • CHR

    CHR - 2022-08-30

    return true; is readable, return static_cast<int>(1); not so much.
    Maybe we should move the discussion to the PR. I don't know if it will be merged as-is.

     
  • Martin

    Martin - 2022-08-31

    The PR is merged now, I'd still argue though that if you actually want have warnings like (with the current head)

    (style) Condition '(Return_t)0' is always false
    

    for

    return (Return_t)0;
    

    then at least the wording of the message should be changed. "condition" and "boolean value" cannot be used completely interchangeably.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.