From 795c06869ceaadf578f0d3bde9edb089d564f619 Mon Sep 17 00:00:00 2001 From: fliiiix Date: Sat, 14 Nov 2026 08:47:40 +0100 Subject: [PATCH] Extend googletest for ACTION macros 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; } ``` --- cfg/googletest.cfg | 11 +++++++++++ test/cfg/googletest.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/cfg/googletest.cfg b/cfg/googletest.cfg index c32eef7274b..e12cac8d372 100644 --- a/cfg/googletest.cfg +++ b/cfg/googletest.cfg @@ -59,4 +59,15 @@ + + + + + + + + + + + diff --git a/test/cfg/googletest.cpp b/test/cfg/googletest.cpp index eaec730136d..6db1f92af4f 100644 --- a/test/cfg/googletest.cpp +++ b/test/cfg/googletest.cpp @@ -42,6 +42,46 @@ namespace ExampleNamespace { } } +namespace ActionNamespace { + int x; + // cppcheck-suppress autoNoType + ACTION(ExampleAction) + { + return x; + } + + int y; + // cppcheck-suppress autoNoType + ACTION_P(ExampleActionP, p) + { + return p + y; + } + + int z; + // cppcheck-suppress autoNoType + ACTION_P3(ExampleActionP3, p0, p1, p2) + { + return p0 + p1 + p2 + z; + } +} + +namespace { + int w; + // cppcheck-suppress autoNoType + ACTION_P2(ExampleActionP2, p0, p1) + { + return p0 + p1 + w; + } +} + +// cppcheck-suppress autoNoType +ACTION(ExampleActionNullPointer) +{ + int *p = 0; + // cppcheck-suppress nullPointer + return *p; +} + TEST(ASSERT, ASSERT) { int *a = (int*)calloc(10,sizeof(int)); // cppcheck-suppress cstyleCast