Closed
Description
Affected rules
- M3-4-1
Description
M3-4-1 raises a false positive while computing the usage or the scope of variables that are template instantiations or constexpr.
Example
namespace a_namespace {
// array of unsigned int
constexpr static unsigned int a_constexpr_var{10U}; // constexpr variable in namespace
static unsigned int a_namespace_var[a_constexpr_var]{}; // a_constexpr_var used in a variable definition
// uses a_namespace_var
constexpr static unsigned int a_namespace_function(void) noexcept {
unsigned int a_return_value{0U};
for (auto loop_var : a_namespace_var) {
a_return_value += loop_var;
}
return a_return_value;
}
// uses a_constexpr_var and a_namespace_var
constexpr static unsigned int another_namespace_function(void) noexcept {
unsigned int a_return_value{0U};
for (unsigned int i{0U}; i < a_constexpr_var; i++) { // M3-4-1 reports a_constexpr_var
// can be moved to this scope but it cannot because
// it is also used in the definition of
// a_namespace_var at the
// namespace scope.
a_return_value += a_namespace_var[i];
}
return a_return_value;
}
} // namespace a_namespace
int main() { return 0; }