Skip to content

cppcoreguidelines-avoid-const-or-ref-data-members gives false positive when a templated class inherits #111985

@Osse

Description

@Osse

When a class with a const ref member inherits a class that deletes move/copy constructors and assignment operators cppcoreguidelines-avoid-const-or-ref-data-members still points out the ref member. This is not an unusual technique (e.g. inheriting from boost::noncopyable). I have written a test case on Compiler Explorer that you can tweak using the #defines.

If the derived class is not a template the check works as expected. If the class is a template but deletes deletes the move/copy constructors and assignment operators itself also works as expected.

Summary:

Is template Inherits False positive
Yes Yes Yes
Yes No No
No Yes No

Also, if the derived class is a template and inherits and deletes the constructors/operators anyway it works as expected. But this is presumably a "sub-case" of the non-inheriting case.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions