Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.NAMESPACE.DECL

Using-declaration in header file.

MISRA-C++ Rule 7-3-6 (required): using-directives and using-declarations (excluding class scope or function scope using-declarations) shall not be used in header files.

This rule is also covered by MISRA.NAMESPACE.DIR and MISRA.NS.USING.HEADER.

Rationale

It is important to ensure that the order of inclusion of header files cannot affect the behaviour of a program.

Example

// f1.h
void foo ( char_t a );

namespace NS1
{
   void foo( int32_t a );
}
inline void bar ( )
{
   foo ( 0 );
}

// f2.h
namespace NS1
{
}

using namespace NS1;

// f1.cc
#include "f1.h"
#include "f2.h"

int32_t m1 ( )
{
   bar ( ); // bar calls foo ( char_t );
}

// f2.cc
#include "f2.h"
#include "f1.h"

void m2 ( )
{
   bar ( ); // bar calls foo ( int32_t );
}

In the above example, changing the order of the header files alters the meaning of the program.