CLion检查和extern声明没有默认构造函数的C ++类

时间:2017-08-23 10:28:37

标签: c++ clion clang-static-analyzer

我有一个工人阶级,例如:

// MyClass.h

class MyClass {
public:

    explicit MyClass(unsigned char enablePin);

    void enable(bool enable);

private:
    const unsigned char mEnabePin;
};
// MyClass.cpp

#include "MyClass.h"
#include <gpio.h>

MyClass::MyClass(unsigned char enablePin) 
    : mEnabePin(enablePin) {
}

void MyClass::enable(bool enable) {
    gpio_set(mEnabePin, static_cast<unsigned char>(enable ? 0 : 1));
}

然后我在另一个文件extern声明了这个类的一个实例:

// main.h

extern MyClass myClass;

当然是一个.cpp文件中的实际定义:

// main.cpp
#include "main.h"
#include <Board.h>

MyClass myClass(Board::Pins::MYCLASS_ENABLE_PIN);

int main() {
    // ...
    myClass.enable(true);
}

使用-Wall -Wextra进行编译时没有任何警告,也可以正常使用。

然而,似乎CLion 2017.2.1没有正确地获得extern声明并总是抱怨:

enter image description here

并向我提供了这些意图行动:

enter image description here

尽管它识别声明定义,因为它将红绿箭头显示为转到定义/声明快捷方式。

我可以关闭这种类型的检查,但它们属于非常有用的类型检查集,即函数参数计数不匹配,我不想关闭它。

enter image description here

有没有人遇到同样的问题并找到了一个整洁的解决方法?

0 个答案:

没有答案