Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A2-10-1: Report type and function identifier hiding #118

Closed
lcartey opened this issue Nov 3, 2022 · 2 comments · Fixed by #546
Closed

A2-10-1: Report type and function identifier hiding #118

lcartey opened this issue Nov 3, 2022 · 2 comments · Fixed by #546
Assignees
Labels
Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@lcartey
Copy link
Collaborator

lcartey commented Nov 3, 2022

Affected rules

  • A2-10-1

Description

A2-10-1 states "An identifier declared in an inner scope shall not hide an identifier declared in an outer scope.". The existing query looks for user defined variables which cause hiding, but functions and types can also be hidden (and cause hiding).

Example

int a;
namespace b {
        void a() { } // NON_COMPLIANT
        int c() { return a; }
}
@lcartey lcartey added false positive/false negative An issue related to observed false positives or false negatives. Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address Impact-Medium labels Nov 3, 2022
@knewbury01 knewbury01 self-assigned this Feb 17, 2024
@ravikprasad ravikprasad added the user-report Issue reported by an end user of CodeQL Coding Standards label Feb 20, 2024
@rvermeulen
Copy link
Collaborator

This is an interesting example that is close to the exception discussed in Autosar, but still marked as non-compliant in the examples in Autosar. It is interesting because like the exception we can still reference a in the global scope as:

int a;
namespace b {
        void a() { }
        int c() { return ::a; }
}

@rvermeulen
Copy link
Collaborator

rvermeulen commented Feb 28, 2024

It seems MISRA C++ 23 completely removes the exceptions in 6.5.1. The also only focus on variables (6.4.1) and member functions (6.4.2)

It is interesting to have the distinction between global namespace and named namespace for the exception since both cases the hidden variable can still be referenced, but in one case it is accepted and the other not. Seems equally confusing as is confirmed by MISRA C++ 23.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

Successfully merging a pull request may close this issue.

4 participants