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.TYPE.NAMECLASH

Type and variable/function with the same name.

MISRA-C Rule 5.6 (advisory): No identifier in one name space should have the same spelling as an identifier in another name space, with the exception of structure member and union member names.

Name space and scope are different. This rule is not concerned with scope. For example, ISO C allows the same identifier '(vector)' for both a tag and a typedef at the same scope.

Example

typedef struct vector { uint16_t x ; uint16_t y; uint16_t z; } vector;
/* Rule violation ^^ ^^                                             */

ISO C defines a number of different name spaces (see ISO/IEC 9899:1990 6.1.2.3 [2]). It is technically possible to use the same name in separate name spaces to represent completely different items. However this practice is deprecated because of the confusion it can cause, and so names should not be reused, even in separate name spaces.

The example below illustrates a violation of this rule in which 'value' is inadvertently used instead of 'record.value':

struct { int16_t key; int16_t value; } record;
int16_t value; /* Rule violation - second use of value */

record.key = 1;
value = 0;    /* should have been record.value */

By contrast, the example below does not violate the rule because two member names are less likely to be confused:

struct device_q { struct device_q *next;   /* ... */ }
devices[N_DEVICES];
struct task_q { struct task_q *next;     /* ... */ }
tasks[N_TASKS];

devices[0].next = &devices[1];
tasks[0].next = &tasks[1];

MISRA-C++ Rule 2-10-6 (required): If an identifier refers to a type, it shall not also refer to an object or a function in the same scope.

Rationale

For C compatibility, it is possible in C++ for a name to refer to both a type and object or a type and function. This can lead to confusion.

Example

typedef struct vector { uint16_t x ; uint16_t y; uint16_t z; } vector;
// Non-compliant ^^                                Non-compliant ^^
        struct vector { uint16_t x ; uint16_t y; uint16_t z; } vector;
// Non-compliant ^^                                Non-compliant ^^