diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 3870f7f4f..10a234da2 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -698,8 +698,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorscope()->type == Scope::eGlobal) + // Declaration in global scope or namespace? + if (tok->scope()->type == Scope::eGlobal || tok->scope()->type == Scope::eNamespace) return; /* { diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 5bdec0bf0..3c3ad8577 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -2130,6 +2130,10 @@ private: check("class X { static const int x[100]; };\n" // #6070 "const int X::x[100] = {0};", false, "test.cpp", false); ASSERT_EQUALS("", errout.str()); + + check("namespace { class X { static const int x[100]; };\n" // #6232 + "const int X::x[100] = {0}; }", false, "test.cpp", false); + ASSERT_EQUALS("", errout.str()); } void buffer_overrun_1_posix_functions() {