User Activity

  • Posted a comment on discussion General Discussion on cppcheck

    Not sure if this is tracked already somewhere: struct Foo { void bar() {} }; int main() { bool b = true; Foo* f = b ? new Foo() : nullptr; if (b) f->bar(); } > cppcheck --version Cppcheck 2.19.0 > cppcheck test.cxx Checking test.cxx ... test.cxx:8:10: warning: Possible null pointer dereference: f [nullPointer] if (b) f->bar(); ^ test.cxx:7:14: note: Assignment 'f=b?new Foo():nullptr', assigned value is 0 Foo* f = b ? new Foo() : nullptr; ^ test.cxx:8:10: note: Null pointer dereference if (b) f->bar();...

  • Posted a comment on discussion General Discussion on cppcheck

    With cppcheck 2.19.0, I see the following regression: void f1(Foo* foo) { double d = 0; if (d!=-99. and foo->func() < 10 ) {} } test.cxx:3:19: error: Syntax Error: AST broken, 'foo' doesn't have a parent. [internalAstError] if (d!=-99. and foo->func() < 10 ) {} ^ Change the 99. to 99 or 99.0 or and to && and the error goes away.

  • Posted a comment on discussion General Discussion on cppcheck

    The following is a minimal reproducer of a syntaxError that we encountered in our code base. The real example was much less evident as it was split over many includes: namespace NS1 { typedef NS2::Bar Bar; using NS2::MyType; } enum E : unsigned int { zero = 0, MyType = 1 }; namespace NS1 { } results in test.cxx:6:1: error: syntax error [syntaxError] enum E : unsigned int { ^ Change or remove any one line, or rename one of the "MyType", and the error goes away.

  • Posted a comment on discussion General Discussion on cppcheck

    The following results in a false positive containerOutOfBounds defect: void f() { auto v = std::vector<std::vector<S*>>(3, std::vector<S*>()); v[2]; } With cppcheck 2.16.0 (and also the current HEAD): test.cxx:3:4: error: Out of bounds access in 'v[2]', if 'v' size is 2 and '2' is 2 [containerOutOfBounds] v[2]; ^ The problem disappears if one omits the default value, i.e. uses auto v = std::vector<std::vector<S*>>(3).

  • Posted a comment on discussion General Discussion on cppcheck

    Another false positive uninitMemberVar in a deleted(!) constructor: struct Foo { Foo() = delete; Foo(int an_int) : i(an_int) {} ~Foo(); int i; }; Foo::~Foo() = default; > cppcheck --enable=warning test.cxx Checking test.cxx ... test.cxx:3:3: warning: Member variable 'Foo::i' is not initialized in the constructor. [uninitMemberVar] Foo() = delete; ^ Moving the = default into the declaration makes it go away.

  • Posted a comment on discussion General Discussion on cppcheck

    Here is another reproducer that may or may not be the same problem: template <class T> struct Foo { Foo() = default; void store (); }; template <class T> void Foo<T>::store() {} Foo<int> foo; void* store = nullptr; results in cppcheck complaining about a non-existent store member: test.cxx:4:3: warning: Member variable 'Foo < int >::store' is not initialized in the constructor. [uninitMemberVar] Foo() = default; ^

  • Posted a comment on discussion General Discussion on cppcheck

    Having a member variable named hash seems to clash with template specializations of std::hash. The following snippet struct Foo {}; namespace std { template<> struct hash<Foo> {}; } struct Bar { Bar(int the_hash) : hash(the_hash) {} int hash; }; results in test.cxx:10:3: warning: Member variable 'Bar::hash' is not initialized in the constructor. [uninitMemberVar] Bar(int the_hash) : hash(the_hash) {} ^ If you rename the member to e.g. _hash the warning disappears. The same happens for other template...

  • Posted a comment on discussion General Discussion on cppcheck

    Hi, the manual says that certain options (e.g. max-template-recursion) are only available via the GUI and not the command line. How is one supposed to set those options when cppcheck is invoked via cmake or using --project=compile_commands.json? Thanks, Frank

View All

Personal Data

Username:
fwinkl
Joined:
2004-04-21 01:17:55
Location:
Switzerland / CEST

Projects

This is a list of open source software projects that Frank Winklmeier is associated with:

Personal Tools

MongoDB Logo MongoDB