Menu

duplicateExpressionTernary false positive with placement new

2024-06-13
2024-06-13
  • Roman Bondar

    Roman Bondar - 2024-06-13

    Hi, this code produces false positive warning
    (style) Finding the same expression in both branches of ternary operator is suspicious as the same code is executed regardless of the condition.

    int* f(void *p_memory)
    {
        return p_memory ? new (p_memory) int : new int; //< Same expression in both branches of ternary operator
    }
    

    I am using 2.14.1 version

     
  • CHR

    CHR - 2024-06-13

    Placement new is not handled well, see e.g. https://trac.cppcheck.net/ticket/10934

     

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.