Main Content

AUTOSAR C++14 Rule M3-2-4

An identifier with external linkage shall have exactly one definition

Description

This checker is deactivated in a default Polyspace® as You Code analysis. See Checkers Deactivated in Polyspace as You Code Analysis (Polyspace Access).

Rule Definition

An identifier with external linkage shall have exactly one definition.

Rationale

If an identifier has multiple definitions or no definitions, it can lead to undefined behavior.

Polyspace Implementation

The checker is not raised on unused code such as

  • Noninstantiated templates

  • Uncalled static functions or extern functions

  • Uncalled and undefined local functions

  • Unused types and variables

Troubleshooting

If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

This example uses two files:

  • file1.cpp:

    typedef signed   int          int32_t;
    
    namespace NS {
    	extern int32_t a;  //Noncompliant
    
    	void foo(){
    		a = 0;
    		
    	}
    }; 
  • file2.cpp:

    typedef signed   int          int32_t;
    typedef signed   long long         int64_t;
    
    namespace NS {
    	extern int64_t a; //Noncompliant
    	void bar(){
    		++a;
    		
    	}
    };

The same identifier a is defined in both files.

Check Information

Group: Basic Concepts
Category: Required, Automated

Version History

Introduced in R2019a