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® 28.0w | AdaCore Inc |
A block contains a declaration of extra that follows an executable statement, which is not allowed under the C89 language rules in effect.
| Class Name | Declaration After Statements |
|---|---|
| Significance | style |
| Mnemonic | PARSE.DECLAFTER |
| Categories | None |
| Availability | Available for C and C++. |
| Enabling | Checks for this warning class are enabled by default.
However, warning instances of this class that are issued as parser
errors (rather than parser warnings)
will be discarded
when using factory configuration settings.
To prevent these instances from being discarded, add the
following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Declaration After Statements" WARNING_FILTER += discard class="Declaration After Statements" |
int parse_declafter(int n) {
n = n + 1;
int extra = n * 2; /* 'Declaration After Statements' warning issued here */
return extra;
}
int calculate_fixed(int value)
{
int extra; /* ok: C89 declaration precedes all statements in the block */
value = value + 1;
extra = value * 2;
return extra;
}
To reproduce this example, analyze it with the following configuration:
WARNING_FILTER += allow class="Declaration After Statements" # Use strict C89 without GNU emulation so the declaration-order check # is isolated from GNU mode and predefined-macro conflicts. COMPILER_MODELS += gcc -> xcc # Enforce the C89 declaration-before-statements restriction; GNU # extension mode otherwise accepts the declaration of extra after a statement. EDG_FRONTEND_OPTIONS_APPEND += --strict_warnings # XCC ignores the native -std option; preserve the requested language revision. EDG_FRONTEND_OPTIONS_APPEND += --c89
gcc -c -std=c89 example.c
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.adacore.com/csm.