Repository navigation
Conversation
|
I had a quick look at some of the failed jobs and they seem not related to my changes is this correct? Or is it expected from me to fixe something to get this change merged? |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
Requesting changes: the PR stops the syntax error but also stops cppcheck from checking ACTION bodies.
- Bodies are no longer analysed (new false negatives).
ACTIONandACTION_Pnow expand to nothing, so the body is left as a bare{ ... }block at namespace scope. Cppcheck doesn't analyse code there. At top level the base config checks these bodies and finds bugs in them; with this PR it reports nothing. The macros should expand to a function header instead, asTESTandMATCHERalready do in this file. I tried that and both the syntax error and the missing warnings went away. ACTION_Pkis not a real gmock macro. gmock usesACTION_P2…ACTION_P10, which this PR doesn't define.ACTION_P2(Foo, p1, p2){}inside a namespace still givessyntaxError. Thekin the PR description is a placeholder, not a macro name.- No tests.
test/cfg/googletest.cppgets no cases for the new defines.
Testing
Built cppcheck from pr/ with make -j8 cppcheck. I didn't build base/: to get the old behaviour I ran the PR's binary with --library=../base/cfg/googletest.cfg. The PR only changes the cfg, so that gives the same results as a base build.
The motivating cases are fixed. namespace{int x;ACTION_P(B, p){}} and namespace{int x;ACTION(B){}} give syntaxError with the base cfg and no error with the PR.
Real ACTION_P2/ACTION_P3 still fail
// c.cpp
namespace{int x;ACTION_P2(Foo, p1, p2){}}$ cppcheck -q --library=googletest c.cpp
c.cpp:1:17: error: syntax error [syntaxError]
Regression: bugs inside ACTION bodies are no longer found
// e.cpp
ACTION(Foo) { int *p = 0; return *p; }
ACTION_P(Bar, n) { char buf[10]; buf[10] = n; return 0; }
void f() { int *p = 0; *p = 1; }With the base cfg (--library=base/cfg/googletest.cfg):
e.cpp:2:37: error: Array 'buf[10]' accessed at index 10, which is out of bounds. [arrayIndexOutOfBounds]
e.cpp:1:35: error: Null pointer dereference: p [nullPointer]
e.cpp:3:25: error: Null pointer dereference: p [nullPointer]
With the PR (--library=googletest), only the warning in f() is left:
e.cpp:3:25: error: Null pointer dereference: p [nullPointer]
--debug shows why: ACTION(Foo) { ... } turns into a bare block at file scope, 1: { int * p@var1 ; p@var1 = 0 ; return * p@var1 ; }, which is never analysed.
The suggested fix works. I tried these defines in a modified copy of the cfg:
ACTION(name)→auto name##Action(int arg0, int arg1)ACTION_P(name,p0)→template<class p0##_type> auto name##ActionP(p0##_type p0, int arg0)
With them, a.cpp and b.cpp have no syntax error and e.cpp reports all three errors again.
Automated review of ac6bae4 by Claude. The pull request was built and tested locally.
c21b1b6 to
e3cb45e
Compare
|
Updated missing things and added some tests cases. |
|
Thanks for running the CI 👍 i will take an other look into it tomorrow seems the new test doesn't do what i expected in ci |
e3cb45e to
87df375
Compare
|
Tests pass now locally: |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
The fixes asked for in the earlier review (C2/C3/C4) are in: the ACTION macros now expand to a function header, ACTION_P2…ACTION_P10 exist, and there are tests.
New problem: the implicit action arguments are declared as int (int arg0, int arg1). In real gmock actions these arguments are often pointers or strings, so the PR causes false positives that did not exist before:
AssignmentIntegerToAddressforchar *s = arg1;invalidPrintfArgType_sforprintf("%s", arg0)
It can also send ValueFlow down the wrong path, because arg0 is assumed to be an integer. Making the argument types template parameters fixes this, for example template<class arg0_type, class arg1_type> auto name(const arg0_type& arg0, const arg1_type& arg1). That also matches gmock, which passes them as const argK_type&. I tested this: the false positives go away, and the real bugs in ACTION bodies are still found.
A smaller point: ACTION declares arg0 and arg1, but ACTION_P* declares only arg0, which is inconsistent.
Earlier comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | ACTION bodies no longer analysed (expand to nothing) | AI review | general | ✅ Fixed |
| 2 | ACTION_Pk is not a real macro; ACTION_P2..P10 missing | AI review | general | ✅ Fixed |
| 3 | No tests in test/cfg/googletest.cpp | AI review | general | ✅ Fixed |
| 4 | Expand ACTION to a function header so the body is analysed | AI review | cfg/googletest.cfg:62 |
✅ Fixed |
| 5 | Add ACTION_P2..ACTION_P10 and tests | AI review | cfg/googletest.cfg:64 |
✅ Fixed |
Testing
I built cppcheck from pr/ and found no build problems. To get the base behaviour I ran the PR binary with --library=../base/cfg/googletest.cfg.
- Motivating cases:
ACTION,ACTION_PandACTION_P2at top level and inside namespaces no longer givesyntaxError. Bugs in ACTION bodies are found (nullPointer,uninitvar). - Regression check:
ACTION_TEMPLATEstill givessyntaxError, but it did before the PR as well, so this is not a regression. - New false positives, caused by
arg0/arg1being declared asint:
// c.cpp
#include <cstring>
#include <cstdio>
ACTION(B4) { char *s = arg1; s[0] = 'a'; }
ACTION_P(B5, v) { const char *s = arg0; return strlen(s) + v; }
ACTION(B6) { printf("%s", arg0); }$ ./cppcheck -q --enable=all --inconclusive --library=googletest c.cpp
c.cpp:3:22: portability: Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]
c.cpp:4:33: portability: Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]
c.cpp:5:14: warning: %s in format string (no. 1) requires 'char *' but the argument type is 'signed int'. [invalidPrintfArgType_s]
The line numbers above are for this 5-line file. In my original test file they were 6, 7 and 8 because of two more ACTION lines.
- Suggested fix: I edited a copy of the cfg so that
ACTIONandACTION_Puse template types (template<class arg0_type, class arg1_type> auto name(const arg0_type& arg0, const arg1_type& arg1), and the same idea forACTION_P). With it, all three warnings above go away. My other scratch files still reportnullPointer,uninitvarandunassignedVariablein ACTION bodies. - Not run: I did not run the full
test/cfgruntests script. The author reports that it passes locally.
Automated review of 87df375 by Claude. The pull request was built and tested locally.
They seem to fail when they are in a namespace
with a statement before the macro.
Motivating examples:
```
namespace{int x;ACTION_P(B, p){}}
namespace{int x;ACTION(B){}}
namespace{int x;ACTION_P3(B, p0, p1, p3){}}
// Regression
ACTION(Foo) { int *p = 0; return *p; }
```
87df375 to
2040587
Compare
|
Made all ACTION* macros a template |
They seem to fail when they are in a namespace
with a statement before the macro.
Motivating examples: