User Activity

  • Posted a comment on discussion General Discussion on cppcheck

    struct S { int * p{nullptr}; }; int main() { S s; s.p = new int[10]; for (int i = 0; i < 10; ++i) { s.p[i] = []() { return 1; }(); } delete[] s.p; return 0; } produces false-memleak.cpp:8:19: error: Memory leak: s.p [memleak] s.p[i] = []() { return 1; }(); ^ Interestingly, using a int * directly (rather than s.p) does not produce the false positive. Replacing the lambda function invocation by a literal or a "normal" function invocation does not trigger the false positive either.

  • Posted a comment on discussion General Discussion on cppcheck

    struct A { int i{0}; const int & operator()() const { return i; } int & operator()() { return i; } }; int getVal(const A & a) { return a(); } void setVal(A & a) { a() = 1; } produces function-call-overload.cpp:8:17: style: Parameter 'a' can be declared with const [constParameter] void setVal(A & a) { a() = 1; } ^ which is incorrect because the non-const overload has to be used. Interestingly, this error goes away when using operator[] instead of operator(). This is closely related to #9266 and may...

  • Posted a comment on discussion General Discussion on cppcheck

    The code int main(int argc, char * argv[]) { const int a = [=]() { if (argc < 1) { return 0; } return 1; }(); if (argc < 1) { return 1; } return 5*a; } produces lambda-return.cpp:9:11: style: Condition 'argc<1' is always false [knownConditionTrueFalse] if (argc < 1) { ^ lambda-return.cpp:3:12: note: Assuming condition 'argc<1' is false if (argc < 1) { ^ lambda-return.cpp:9:11: note: Condition 'argc<1' is always false if (argc < 1) { ^

View All

Personal Data

Username:
st_loeffler
Joined:
2004-02-27 11:42:01

Projects

This is a list of open source software projects that Stefan Löffler is associated with:

Personal Tools