Cppcheck失败的原因“返回了对自动变量的引用”?

时间:2018-08-01 14:31:27

标签: c++ qt cppcheck

我看到以下Cppcheck,但不明白为什么得到它:

directoryutils.cpp 173 error returnReference false Reference to auto variable returned.

我既不明白为什么会返回auto变量,也不清楚“参考部分”。那是假阳性吗?

标题:static const FilePerApplication &applicationDataDirectoryMapWithoutCurrentVersion();

const CDirectoryUtils::FilePerApplication &CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion()
{
  static const FilePerApplication dirs = [ = ] {
      FilePerApplication directories;
      for (const QFileInfo &info : CDirectoryUtils::applicationDataDirectories())
      {
        .... fill in data ....
        directories.insert(info.filePath(), appInfo);
      }
      return directories; // LINE 173 why auto???
  }();

  return dirs;
}
  1. 备注:using FilePerApplication = QMap<QString, CApplicationInfo>;
  2. 备注:像这里https://stackoverflow.com/a/9620143/356726一样,给它一个显式的返回类型-> FilePerApplication不会使检查错误失效

0 个答案:

没有答案