A7-1-2
: Query proposes to add constexpr to non-static data members (and other problems)
#789
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
Standard-AUTOSAR
Affected rules
Description
1.
constexpr
on non-static data membersThis query should exclude variables that are non-static data members. This is because the compiler raises an error in case a non-static data member is marked as
constexpr
.Example
Fixing as per the alerts raised by CodeQL in the test case of this query (e.g. here or here) also raises the error.
2.
constexpr
on member variables updated in un-instantiated templatesThis query alerts to add constexpr to member variables which are only used in uninstantiated template functions. At first glance, it seems to be correct because since the template function is not instantiated, the member variable isn't getting accessed anywhere and hence becomes a candidate for adding constexpr. However, when the user attempts to fix it, the compiler raises an error and points to the modification in the uninstantiated template function. So should we avoid member variables of templates?
Example
Note: The error about
size_
being a non-static data member and constexpr also exists but even if we make it static, we cant fix the error because compiler complains about the update onsize_
in the uninstantiated template functionadd()
.3.
constexpr
for range-based for loop variablesI'm not able to provide a reproducible case but this query alerts on variables used in range-based for loop.
Example
The reason is that when the range based for loop is de-sugared there is an assignment like the following:
We have an
operator*
as an initializer expression and it has a variable access to the__begin
variable. The line; “any(Call call | isCompileTimeEvaluatedCall(call))...” here is True for this case because theoperator *
is marked asconstexpr
by CodeQL and the getAnArgument() here for this call doesn’t return any arguments. Please note that, the qualifier for this call expression is the__begin
variable which is compiler generated. So should we avoid such calls which has a qualifier that hasVariableAccess
to variables that are compiler generated?The text was updated successfully, but these errors were encountered: