【问题标题】:Warning - Unreferenced inline function has been removed警告 - 未引用的内联函数已被删除
【发布时间】:2016-09-28 10:02:12
【问题描述】:

我开始学习 C++,并了解到提高警告级别是一个好主意,以便在编写代码时更加小心。我正在使用 Visual Studio 2015(社区版)

但是,在这样做之后,即使在基本程序中,我也会收到数百个错误(编辑:警告被视为错误,抱歉)。这些都来自数学标题,他们说“未引用的内联函数已被删除”。似乎我不使用的每种方法都会引起警告。

为什么会发生这种情况,我该如何解决?

【问题讨论】:

  • 请显示您收到的其中一些错误。
  • 唯一的解决办法是不使用/WAll,很遗憾。
  • 您不能“发现错误”。错误就是错误,不能决定什么是错误,什么不是(唯一的例外:将警告视为错误选项)。您可以提高 警告 级别。如果这是您所指的,请更新您的问题。

标签: c++ visual-studio visual-studio-2015


【解决方案1】:

对于 Visual C++,您应该使用 /W4,而不是 /Wall,这是不切实际的。如果警告级别 4 仍然产生愚蠢的警告,例如从标准头文件,然后考虑使用我的旧 MSVC "no sillywarnings" header,或者它的合适扩展。然后最好通过强制包含编译器选项。

为了在命令行中使用 Visual C++,我通常使用以下环境变量:

CL=/nologo /EHsc /GR /W4 /FI "iso646.h"

显然现在可以自动抑制来自系统标头的警告,所以这不是问题。


请注意,虽然神圣的 C++ 标准并未区分不同类型的诊断,但作为事实上标准的 C++ 编译器和链接器会区分

  • 错误
    错误诊断意味着没有生成可执行文件(或目标文件)。

  • 警告
    警告诊断意味着某事可能有问题,或者至少有些问题,但编译器或链接器或其他工具会假设您知道自己在做什么。


您可以强制包含的相关 MSVC 特定标头(选项 /FI),包括更新版本的 no sillywarnings 标头:

msvc_less_errors_as_warnings_please.hpp
#pragma once
// p/cppx/core_language_support/compiler_specific/msvc_less_errors_as_warnings_please.hpp
// Copyright © Alf P. Steinbach 2015. Boost Software License 1.0.

#ifndef _MSC_VER
#   error This file is specific to the MSVC (Microsoft Visual C++) compiler.
#endif

#pragma warning( error: 4566 )      // Character ... cannot be represented  --  is error.
#pragma warning( error: 4627 )      // Source code has been ignored  –  is error.
msvc_more_warnings_please.hpp
#pragma once
// p/cppx/core_language_support/compiler_specific/msvc_more_warnings_please.hpp
// Copyright © Alf P. Steinbach 2015. Boost Software License 1.0.

#ifndef _MSC_VER
#   error This file is specific to the MSVC (Microsoft Visual C++) compiler.
#endif

#pragma warning( push, 4 )      // Warning level 4 (max). MSVC /Wall is impractical.
msvc_no_sillywarnings_please.hpp
#pragma once
// p/cppx/core_language_support/compiler_specific/msvc_no_sillywarnings_please.hpp
// Copyright © Alf P. Steinbach 2010 – 2015. Boost Software License 1.0.

#ifndef _MSC_VER
#   error This file is specific to the MSVC (Microsoft Visual C++) compiler.
#endif

#ifndef CPPX_ALLOW_WP64
#   // The /Wp64 option generates spurious warnings when a __w64 type argument selects
#   // a correct overload with non-__w64 formal argument type, i.e. for <<. In newer
#   // versions of MSVC this option is deprecated. It Really Annoyed a lot of people!
#   ifdef  _Wp64
#       error Do not use the /Wp64 option: use a 64-bit compiler to detect 64-bit portability issues.
#   endif
#endif

// The following are real warnings but are generated by almost all MS headers, including
// standard library headers, so it's impractical to leave them on.
#pragma  warning( disable: 4619 )   // there is no warning number 'XXXX'
#pragma  warning( disable: 4668 )   // XXX is not defined as a preprocessor macro

// The following are pure sillywarnings:
#pragma warning( disable: 4061 )    // enum value is not *explicitly* handled in switch
#pragma warning( disable: 4063 )    // case 'nn' is not a valid value for switch of enum 'Name'
#pragma warning( disable: 4099 )    // first seen using 'struct' now seen using 'class'
#pragma warning( disable: 4127 )    // conditional expression is constant
#pragma warning( disable: 4180 )    // qualifier applied to function type has no meaning
#pragma warning( disable: 4217 )    // member template isn't copy constructor
#pragma warning( disable: 4250 )    // inherits (implements) some member via dominance
#pragma warning( disable: 4251 )    // needs to have dll-interface to be used by clients
#pragma warning( disable: 4275 )    // exported class derived from non-exported class
#pragma warning( disable: 4347 )    // "behavior change", function called instead of template
#pragma warning( disable: 4355 )    // "'this': used in member initializer list
#pragma warning( disable: 4373 )    // override when arg types differ by const/volatile qualifiers
#pragma warning( disable: 4428 )    // MSVC 9: universal-character-name encountered in source
#pragma warning( disable: 4459 )    // local declaration hides global declaration
#pragma warning( disable: 4505 )    // unreferenced function has been removed
#pragma warning( disable: 4510 )    // default constructor could not be generated
#pragma warning( disable: 4511 )    // copy constructor could not be generated
#pragma warning( disable: 4512 )    // assignment operator could not be generated
#pragma warning( disable: 4513 )    // destructor could not be generated
#pragma warning( disable: 4610 )    // can never be instantiated user defined constructor required
#pragma warning( disable: 4623 )    // default constructor could not be generated
#pragma warning( disable: 4624 )    // destructor could not be generated
#pragma warning( disable: 4625 )    // copy constructor could not be generated
#pragma warning( disable: 4626 )    // assignment operator could not be generated
#pragma warning( disable: 4640 )    // a local static object is not thread-safe
#pragma warning( disable: 4646 )    // noreturn function should have a void return type
#pragma warning( disable: 4661 )    // a member of the template class is not defined.
#pragma warning( disable: 4670 )    // a base class of an exception class is inaccessible for catch
#pragma warning( disable: 4672 )    // a base class of an exception class is ambiguous for catch
#pragma warning( disable: 4673 )    // a base class of an exception class is inaccessible for catch
#pragma warning( disable: 4675 )    // resolved overload was found by argument-dependent lookup
#pragma warning( disable: 4702 )    // unreachable code, e.g. in <list> header.
#pragma warning( disable: 4710 )    // call was not inlined
#pragma warning( disable: 4711 )    // call was inlined
#pragma warning( disable: 4820 )    // some padding was added
#pragma warning( disable: 4917 )    // a GUID can only be associated with a class, interface or namespace
#pragma warning( disable: 4996 )    // MSVC 9: a C stdlib function has been "deprecated" (says MS)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 2021-03-24
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多