Kitware / KWStyle

Kitware Style Checker
Other
53 stars 30 forks source link

Incorrect "Encapsulation not preserved" error #45

Open msmolens opened 7 years ago

msmolens commented 7 years ago

With KWStyle.xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<Description>
<InternalVariables>m_[A-Z],0,1</InternalVariables>
</Description>

and Outer.h:

class Outer
{
public:
    Outer() {}

private:
    class Inner
    {
    public:
        Inner() {}
    };

    Inner m_Inner;
};

KWStyle shows an error:

$ KWStyle -xml KWStyle.xml -v Outer.h -gcc
Processing Outer.h
Error #1 (0) Encapsulation not preserved

The error refers to the Inner m_Inner; line and suggests that the internal variable m_Inner is not in a protected or private section. However, it's clear that m_Inner is in a private section.

Tested with Kitware/KWStyle@0620fdd3ef07d124514331ae35c22b7a4c1d0d71.

aylward commented 7 years ago

The nested class definitions is not handled correctly. Good catch!

One way to fix this is to update KWStyle/kwsParser.h/.cxx with a function to determine scope and then FindArea should only find tags (public, private, ...) that are at the same scope.

s

On Tue, Nov 29, 2016 at 12:15 PM, Max Smolens notifications@github.com wrote:

With KWStyle.xml:

<?xml version="1.0" encoding="iso-8859-1"?>

m_[A-Z],0,1

and Outer.h:

class Outer { public: Outer() {}

private: class Inner { public: Inner() {} };

Inner m_Inner;

};

$ KWStyle -xml KWStyle.xml -v Outer.h -gcc Processing Outer.h Error #1 (0) Encapsulation not preserved

The error refers to the Inner m_Inner; line and suggests that the internal variable m_Inner is not in a protected or private section. However, it's clear that m_Inner is in private section.

Tested with Kitware/KWStyle@0620fdd https://github.com/Kitware/KWStyle/commit/0620fdd3ef07d124514331ae35c22b7a4c1d0d71 .

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Kitware/KWStyle/issues/45, or mute the thread https://github.com/notifications/unsubscribe-auth/AAREr8l7wL5Kigb8__BTeNuqfngE7NeAks5rDF2zgaJpZM4K_PSg .

--

Stephen R. Aylward, Ph.D. Senior Director of Operations, North Carolina, Kitware, Inc. http://www.kitware.com and http://www.aylward.org (919) 969-6990 x300