Menu

False negative for identicalConditionAfterEarlyExit with constexpr

Vit Kucera
2026-06-25
2026-06-26
  • Vit Kucera

    Vit Kucera - 2026-06-25

    Version: e0014e1b023442e9c0e15609658a910c41436356

    void test(bool a, bool b)
    {
      if (a) {
        return;
      }
      if (a || b) { // true positive for identicalConditionAfterEarlyExit
        return;
      }
    }
    
    template <bool a, bool b>
    constexpr void test_constexpr()
    {
      if constexpr (a) {
        return;
      }
      if constexpr (a || b) { // false negative for identicalConditionAfterEarlyExit if function is called, true positive if it is not called
        return;
      }
    }
    
    int main()
    {
      test(true, false);
      test_constexpr<true, false>();
      return 0;
    }
    
     
  • CHR

    CHR - 2026-06-26

    Thanks for reporting, I have added your example in https://trac.cppcheck.net/ticket/8334

     
    👍
    1
  • Vit Kucera

    Vit Kucera - 2026-06-26

    Thanks

     

Log in to post a comment.

Auth0 Logo