codeql-coding-standards icon indicating copy to clipboard operation
codeql-coding-standards copied to clipboard

`A2-10-5`: id name reuse false positive with template specialization

Open fjatWbyT opened this issue 1 year ago • 2 comments

Affected rules

  • A2-10-5

Description

Variable template defined with an specialization is alerted as identifier reuse.

Example

template<typename T, typename S>
extern constexpr bool x = false;

template<typename T>
extern constexpr bool x<T, int> = true;

Query IdentifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReused.ql warns about x in lines 2 and 5.

fjatWbyT avatar Dec 02 '24 02:12 fjatWbyT

Fix proposal: I think that template specializations could be added as an exception, although I am unsure how to capture that. I also wondered whether it should be using the template instantiated or instantiation CodeQL classes.

fjatWbyT avatar Dec 02 '24 02:12 fjatWbyT

Thanks! I agree, we should ignore specializations.

The standard library currently does not provide a variable template specialization class, but this can be implemented in CodeQL by looking for uninstantiated templates where one or more template arguments have been provided.

lcartey avatar Dec 10 '24 11:12 lcartey