08-08-2025, 08:06 AM
The amplification of rule 6.8.4 leads with this sentence to clarify to which member functions this rule applies:
The usage of the word “designates” here is ambiguous.
Does it mean the expression . . .
Depending on which interpretation is true, the following code examples are either
compliant or non-compliant:
The intent of the rule seem to support meaning number 2, which would mean only A::Get is non-compliant.
If that is the case, we suggest to replace “designates” with a less ambiguous phrase, e.g. “references/points to” or to explain more clearly what is meant in the amplification.
In addition, clarifying examples for these cases would be helpful.
Quote:This rule applies to member functions with reference or pointer return type, where, in the definition of the function, at least one
return expression explicitly designates this, *this or a subobject of *this.
The usage of the word “designates” here is ambiguous.
Does it mean the expression . . .
- . . . is (or evaluates to something that is) this, *this or a subobject of *this?
- . . . refers/points to (or evaluates to something that refers/points to) this, *this or a subobject of *this?
- . . . contains this, *this or a subobject of *this in any shape or form?
- A combination of the above?
Depending on which interpretation is true, the following code examples are either
compliant or non-compliant:
Code:
class A {
std::int32_t data_;
public:
// returns a pointer to data member
std::int32_t const* Get() const { return &data_; }
};
class B {
std::int32_t* ptr_;
public:
// returns data member which is a pointer to an
// object with lifecycle independent of "this"
std::int32_t* Get() const { return ptr_; }
};
class C {
std::int32_t idx_;
public:
// returns unrelated pointer based on data member
float const* Get(std::array<float,10> const& data) const { return &data[idx_]; }
};
The intent of the rule seem to support meaning number 2, which would mean only A::Get is non-compliant.
If that is the case, we suggest to replace “designates” with a less ambiguous phrase, e.g. “references/points to” or to explain more clearly what is meant in the amplification.
In addition, clarifying examples for these cases would be helpful.