4Manuals

  • PDF Cloud HOME

来自std :: chrono的编译器警告,但未使用 Download

    获取Hough线的交点OpenCV C ++ 如何将字符串“ text1”设置为包含项目text1,text2,test3的组合框的选定项目? 为什么System.Net.Mail.MailAddress构造函数在域部分中解析带有斜杠“ /”的电子邮件? Android 10,API29:在应用程序文件夹中使用C ++库编写文件会使应用程序崩溃 Unity-LineRenderer没有出现在版本(2D)上 按下按钮后,电话中未显示通知 ASP.net,使用WebConfig httpErrors重定向到区域内的控制器不起作用 获取会议室详细信息 我们如何将参数Line转换为Station? 网络核心:查找实体框架核心的主键和反射

使用VC2019在警告级别3上出现涉及std::chrono的奇数警告。这是处理命令行标志的简化代码。我已经删除了与该问题无关的大多数胆量。

#if 1   // enable bug
#include <chrono>   // excluding this also eliminates chrono warnings
using CorrectedIntType=int;
#else
using CorrectedIntType=size_t;
#endif

#include <iostream>
#include <vector>
#include <string>
#include <type_traits>

using std::vector;
using std::string;

namespace {
    void fixup(const std::string& argcmd, std::string& arg) { arg = argcmd; }

    template<class T>
    void procVal(std::vector<std::string>& arglist, CorrectedIntType idx, T& arg)
    {
        fixup(arglist[idx], arg);
        arglist.erase(arglist.begin() + idx);
    }

    template<class T, class ...TA>
    void procVal(std::vector<std::string>& arglist, CorrectedIntType idx, T& arg, TA&...argv)
    {
        procVal(arglist, idx, arg);
        procVal(arglist, idx, argv...);
    }

    template<class T, class ...TA>
    bool procFlag(const char* pc, std::vector<std::string>& arglist, T& arg1, TA&...argv)
    {
        std::string flag(pc);
        for (size_t i = 0; i < arglist.size(); i++)
        {
            if (arglist[i] == flag)
            {
                arglist.erase(arglist.begin() + i);
                procVal(arglist, i, arg1);      // process one argument after flag
                return true;
            }
        }
        return false;
    }
}

int main()
{
    string outfile;
    vector<string> test = { "test" };
    procFlag("-o", test, outfile);      // assigns test[0] to outfile and removes it
    std::cout << outfile << '\n';
}

警告:

1>Source.cpp
1>C:\Users\mgray\Documents\Visual Studio 2017\Projects\CommandLineCPP\stackoverflow\Source.cpp(1343,1): warning C4267: 'argument': conversion from 'size_t' to 'CorrectedIntType', possible loss of data
1>C:\Users\mgray\Documents\Visual Studio 2017\Projects\CommandLineCPP\stackoverflow\Source.cpp(1362): message : see reference to function template instantiation 'bool `anonymous-namespace'::procFlag<std::string,>(const char *,std::vector<std::string,std::allocator<std::string>> &,T &)' being compiled
1>        with
1>        [
1>            T=std::string
1>        ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.24.28314\include\chrono(632): message : see reference to class template instantiation 'std::chrono::duration<double,std::ratio<1,1>>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.24.28314\include\chrono(178): message : see reference to class template instantiation 'std::chrono::duration<__int64,std::nano>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.24.28314\include\chrono(610): message : see reference to class template instantiation 'std::chrono::time_point<std::chrono::steady_clock,std::chrono::nanoseconds>' being compiled
1>Done building project "stackoverflow.vcxproj".

尽管代码可以正常工作,即使存在int -<> size_t转换问题,但当顶部的宏设置为0时,所有警告都会消失。我担心chrono警告的存在是因为它不是。涉及。这是VS2019中的错误吗?关于为何发生chrono警告的任何想法?

使用编译器资源管理器link to godbolt

0 个答案:

没有答案



Similar searches
    Jupyter中的正则表达式规则 如何使用PHP将https错误状态设置为404,以便可以通过.htaccess文件处理? 应用程序可在调试版本中运行,但会在发行版本中中断 线性回归Python中的值错误-数组长度与索引长度不匹配 大家好,我正在学习Python 3,但对While循环感到困惑。有人可以帮助我了解“ **,而真实:**”