Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
langcpp
// a.h
#ifndef A_HEADER_FILE
#define A_HEADER_FILE
 
namespace {
int v;
}
 
inline int get_v() { return v; }
 
#endif // A_HEADER_FILE
 
// a.cpp
#include "a.h"
 
void f() {
  int i = get_v();
  // ...
}
 
// b.cpp
#include "a.h"
 
void g() {
  int i = get_v();
  // ...
}

See MSC52DCL60-CPP. Obey the oneOne-definition ruleDefinition Rule for more information on violations of the one-definition rule.

...

Tool

Version

Checker

Description

Clang
Include Page
Clang_V
Clang_V
 google-build-namespaces
Checked by clang-tidy
LDRA tool suite
Include Page
LDRA_V
LDRA_V

286 S, 512 S

Fully implemented

Parasoft C/C++test9.5CODSTA-74 
SonarQube C/C++ Plugin
Include Page
SonarQube C/C++ Plugin_V
SonarQube C/C++ Plugin_V
UnnamedNamespaceInHeader 

...

Bibliography

[ISO/IEC 14882-2014]

Subclause 3.2, "One Definition Rule"
Subclause 7.1.2, "Function Specifiers"
Subclause 7.3.1, "Namespace Definition"

...