c++:需要正确的语法以避免 MISRA 14-6-1 警告。 Class 具有相关基础的模板 class

c++: Need correct syntax to avoid MISRA 14-6-1 warning. Class template with dependent base class

我已经为一种叫做 SML 的语言编写了 lexer/parser。它用于电子仪表。我正处于静态代码分析阶段。 Lint 正在报告 MISRA 违规行为 14-6-1。规则(必需)是:"In a class template with a dependent base, any name that may be found in that dependent base shall be referred to using a qualified-id or this->"

系统:Raspberry PI3B,g++:cc 版本 4.9.2(Raspbian4.9.2-10),PC LINT v9.0k。语言:C++98

代码摘录:

class SmlElementBase
{
    public:
        SmlElementBase(void) {}
        virtual ~SmlElementBase(void) {}                    
        // Main "parse" pure function to be implemented / overwritten by     all derived classes
        virtual prCode parse(ParserContext &pc) = 0;        
        // Per default an SML Element is not a container
        virtual boolean isContainer(void) const { return false; }
};

template<const Token::TokenType tokenType, const TokenLength TokenLength=0UL>
class SmlPrimitive : public SmlElementBase
{
    public:
        SmlPrimitive(void) : SmlElementBase() {}
        virtual ~SmlPrimitive(void) {}
        virtual prCode parse(ParserContext &pc);    // Parse function     (calls match function)

    protected:      
        virtual boolean match(const Token *token);  // Match token with     expected type and length
};

template<typename ValueType, const Token::TokenType tokenType, const TokenLength tokenLength=0UL>
class SmlPrimitiveWithValue : public SmlPrimitive<tokenType, tokenLength>
{
    public:
        //lint -e{1960,915,919}
        SmlPrimitiveWithValue(void) : SmlPrimitive<tokenType, tokenLength>(), value() {}; 
        // SmlPrimitiveWithValue(void) : SmlPrimitive<tokenType, tokenLength>(), value::SmlPrimitive() {};     NO DIFFERENCE
        virtual ~SmlPrimitiveWithValue(void) {}
        // Parse function is inherited. 
        //lint -e{1925}
        ValueType value;    // Value will be stored here. Public because of visitor pattern
    protected:
        virtual ::boolean match(const ::Token *token); // Match token with expected type and length and store value
};

typedef SmlPrimitiveWithValue<u8, Token::UNSIGNED_INTEGER, 1UL>             Unsigned8;

Lint 报告如下:

SmlPrimitiveWithValue(void) : SmlPrimitive<tokenType, tokenLength>(), value() {}; 

注释 1942:不合格的名称 'SmlPrimitive' 由于依赖基数 class 而被误解 [MISRA C++ 规则 14-6-1]

对于 SmlPrimitiveWithValue 的构造函数。

避免违反 MISRA 规则的正确语法是什么?

我用谷歌浏览器试了又试,但想不出解决办法。

编辑:

我也试过:

SmlPrimitiveWithValue(void) : ::SmlPrimitive<tokenType, tokenLength>::SmlPrimitive(), value() {}; 

这不编译。编译器消息:

/home/pidata/project/ehz/include/parser.hpp: In constructor ‘ParserInternal::SmlPrimitiveWithValue<ValueType, tokenType, tokenLength>::SmlPrimitiveWithValue()’:
/home/pidata/project/ehz/include/parser.hpp:281:50: error: expected template-name before ‘<’ token
      SmlPrimitiveWithValue(void) : ::SmlPrimitive<tokenType, tokenLength>::SmlPrimitive(), value() {};
                                                  ^
/home/pidata/project/ehz/include/parser.hpp:281:50: error: expected ‘{’ before ‘<’ token

这有点傻,因为非限定名称(不用于 class 成员访问)是 not looked up in dependent bases at all。因此,根据与定义不同的专业化解释,不可能出现(比如说)格式错误的 NDR。

反正指南要的就是让你写

SmlPrimitiveWithValue(void) : ::SmlPrimitive<tokenType, tokenLength>(), value() {};

(无论名称空间包含 SmlPrimitive,如果有的话)。也就是说,用 qualified-id.

命名基 class