JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


PARSE.DBNR : Declared but Not Referenced

Summary

A function or object is declared with file static or narrower scope, but is not used within the scope of the declaration.

See also Unused Variable.

This warning class is derived from a C/C++ parser warning.

Properties

Class Name Declared but Not Referenced
Significance style
Mnemonic PARSE.DBNR
Categories
MisraC2025 MisraC2025:2.8 A project should not contain unused object definitions
MisraC2023 MisraC2023:2.8 A project should not contain unused object definitions
Misra2012 Misra2012:2.8 A project should not contain unused object definitions
AUTOSARC++14 AUTOSARC++14:A0-1-3 Every function defined in an anonymous namespace, or static function with internal linkage, or private member function shall be used.
  AUTOSARC++14:M0-1-3 A project shall not contain unused variables.
  AUTOSARC++14:M0-1-4 A project shall not contain non-volatile POD variables having only one use.
MisraC++2008 MisraC++2008:0-1-3 A project shall not contain unused variables.
  MisraC++2008:0-1-4 A project shall not contain non-volatile POD variables having only one use.
  MisraC++2008:0-1-10 Every defined function shall be called at least once.
MisraC++2023 MisraC++2023:0.2.1 Variables with limited visibility should be used at least once
  MisraC++2023:0.2.4 Functions with limited visibility should be used at least once
CWE CWE:563 Assignment to Variable without Use
CERT-C CERT-C:MSC12-C Detect and remove code that has no effect or is never executed
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Declared but Not Referenced"

Example

static int i1 = 1;            // 'Declared but Not Referenced' warning issued here
int i2 = 2;                                        // unused but has external linkage
static int i3 = 3;                                 // used to define f4()

static void f1(int i){}       // 'Declared but Not Referenced' warning issued here
void f2(int i) {}                                  // unused but has external linkage
static void f3(int i){                             // used to define f4()
    int a;                    // 'Declared but Not Referenced' warning issued here
                              //  ('Unused Variable' warning also issued)
}
static void f4(int i){        // 'Declared but Not Referenced' warning issued here
    f3(i3);
}

namespace mynamespace {
    static int mi1 = 1;       // 'Declared but Not Referenced' warning issued here
    int mi2 = 2;                                   // unused but has external linkage
    static int mi3 = 3;                            // used to define mns4()

    static void mns1(int i){} // 'Declared but Not Referenced' warning issued here
    void mns2(int i){}                             // unused but has external linkage
    static void mns3(int i){                       // used to define mns4()
        int a;                // 'Declared but Not Referenced' warning issued here
                              //  ('Unused Variable' warning also issued)
    }
    static void mns4(int i){  // 'Declared but Not Referenced' warning issued here
        mns3(mi3);
    }
}

namespace {
    static int ai1 = 1;       // 'Declared but Not Referenced' warning issued here
    int ai2 = 2;              // 'Declared but Not Referenced' warning issued here
    static int ai3 = 3;                            // used to define ans4()

    static void ans1(int i){} // 'Declared but Not Referenced' warning issued here
    void ans2(int i){}        // 'Declared but Not Referenced' warning issued here
    static void ans3(int i){                       // used to define ans4()
        int a;                // 'Declared but Not Referenced' warning issued here
                              //  ('Unused Variable' warning also issued)
    }
    static void ans4(int i){  // 'Declared but Not Referenced' warning issued here
      ans3(ai3);
    }
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.