Menu

unusedStructMember false positive with Google Test

2024-04-29
2024-05-17
  • Steve Albright

    Steve Albright - 2024-04-29

    2.14

    style: unusedStructMember - class member 'ExampleTestFixture::MODE_OFF' is never used

    class ExampleTestFixture: public ::Test
    {
    public:
    static constexpr bool MODE_OFF = false;
    };

    TEST_F(ExampleTestFixture, ShowFalsePositive)
    {
    EXPECT_FALSE(MODE_OFF);
    }

    if you change to

    TEST_F(ExampleTestFixture, ShowFalsePositive)
    {
    EXPECT_FALSE(ExampleTestFixture::MODE_OFF);
    }

    it works so maybe some scope confusion.

     

    Last edit: Steve Albright 2024-04-29
  • Steve Albright

    Steve Albright - 2024-05-14

    So, what is going on with this one, I am having to add way too many suppression for it.

     
  • CHR

    CHR - 2024-05-14

    TEST_F is defined as just string concatenation: <define name="TEST_F(A,B)" value="void __ ## A ## _ ## B ( )"/>
    So there is no relation to the data type anymore.

     
    • Steve Albright

      Steve Albright - 2024-05-14

      It's a lot of new failures we didn't have before and I'd rather not globally turn the check off.

      Surely the gtest framework could/should be accomidated?

      Maybe you are just pointing out the concern related on how to fix?

      Note, TEST() is another construct.

       
      • CHR

        CHR - 2024-05-15

        You are using --library=googletest, right? That is all the accomodation we have (in googletest.cfg).

         
        • Steve Albright

          Steve Albright - 2024-05-17

          No, we were not and that looks to make a nice difference and I added in other libraries too.

          I was unsure if you could put multiple libraries on the same line or not and what that format would be. It isn't shown in the user's manual, so I did each library on a separate line.

          I went back to a large repo that was already clean and by adding the libraries change it found many more warnings so thanks for this suggestion.

           

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.