File tree Expand file tree Collapse file tree 2 files changed +14
-64
lines changed
cpp/misra/test/rules/RULE-10-3-1 Expand file tree Collapse file tree 2 files changed +14
-64
lines changed Original file line number Diff line number Diff line change 11#include " test.hpp"
2+ #include < cassert>
23
3- /*
4- * This file demonstrates that anonymous namespace variables
5- * in headers create translation-unit-local copies.
6- */
4+ extern void setValues ();
5+ extern std::int32_t getX_File1 ();
6+ extern std::int32_t getNested_File1 ();
77
8- void setValues () {
9- x = 42 ; // Sets file1.cpp's copy of x
10- MyNamespace::y = 42 ; // Sets the shared y
11- z = 42 ; // Sets the shared z
12- Outer::nested = 42 ; // Sets file1.cpp's copy of nested
13- }
8+ /* ========== 6. Compliant: anonymous namespace in .cpp file ========== */
9+
10+ namespace { // COMPLIANT: anonymous namespace in source file is fine
11+ std::int32_t localVar = 0 ;
1412
15- std:: int32_t getX_File1 () {
16- return x ; // Returns file1.cpp's copy of x
13+ void localHelper () {
14+ localVar = 100 ; // Only visible in this TU, as expected
1715}
16+ } // namespace
1817
19- std::int32_t getNested_File1 () {
20- return Outer::nested; // Returns file1.cpp's copy of nested
18+ int main () {
19+ localHelper ();
20+ return 0 ;
2121}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments