views:

67

answers:

2

I am using PC-Lint (great tool for static code analysis - see http://www.gimpel.com/) For the following chunk of code:

class ASD {
    protected:
        template<int N>
        void foo();
};

template<>
inline void ASD::foo<1>() {}

template<int N>
inline void ASD::foo() {}

PC-lint gives me a warning:

inline void ASD::foo<1>() {}
mysqldatabaseupdate.h(7) : Error 1060: protected member 'ASD::foo(void)' is not accessible to non-member non-friend functions

I believe the code is fine and the error is on the lint side, but I think Lint tool is REALLY great tool and it's more likely than I don't know something. So is this code OK?

+2  A: 

You have only one function foo in your struct ASD and it is in the protected section. It is not accessible from non-member functions. At the same time struct ASD doesn't have any other member functions. So nobody have access to foo, I believe this is the reason for that error message.

Try to change your struct to the following, for example:

class ASD {
    public:
        void bar() { foo<1>(); }
    protected:
        template<int N>
        void foo();
};
Kirill V. Lyadvinsky
But wouldn't any arbitrary child classes have access to the `foo` function?
Mark B
In this example, and I believe in the code which produces the error there are no child classes.
Kirill V. Lyadvinsky
Try adding a virtual function to the class. It may do a trade-off here.
Johannes Schaub - litb
A: 

The bug was in PC-Lint itself. It has been fixed in the newest version.

ssobczak