Menu

false positive - syntaxError brace initialization with explicit operator call

2025-09-23
2025-09-23
  • Joel Shuman

    Joel Shuman - 2025-09-23

    Hello,
    I just wanted to report a false positive syntaxError. My team uses brace init everywhere we can and we have some templates that make calls using explicit operator calls to get a value. Here is a simple example without a template.

    #include <iostream>
    #include <cstdint>
    
    struct callable
    {
        int operator()() { return 42; }
    };
    
    int main()
    {
        callable c;
        std::int32_t const myint = c.operator()(); // <-- No syntaxError from cppcheck
        std::cout << myint << '\n';
    
        std::int32_t const anotherint{ c.operator()() }; // <-- This produces a syntaxError from cppcheck
        std::cout << anotherint << '\n';
    }
    

    This does not seem specific to the call operator. I have also seen this false positive with auto const data{ operator->() };

    I can work-around this easily enough, but I wanted to report the false positive.

    I tested this using cppcheck 2.18.3.

    Thank you!
    Joel

     

    Last edit: Joel Shuman 2025-09-23
  • Oliver Stöneberg

    Thanks for reporting. I filed https://trac.cppcheck.net/ticket/14151 about it.

     
    ❤️
    1

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.