2016-05-30 17 views
6

Sto iniziando a imparare C++ e ho letto che aumentare il livello di avviso è una buona idea per essere più attenti nello scrivere il codice. Sto usando Visual Studio 2015 (versione di comunità)Avviso - La funzione inline non referenziata è stata rimossa

Tuttavia, dopo averlo fatto, ricevo centinaia di errori (modifica: AVVISI trattati come errori, scusate) anche nei programmi di base. Questi vengono tutti dall'intestazione matematica e dicono che "la funzione inline non referenziata è stata rimossa". Sembra che ogni metodo che non uso stia causando un avvertimento.

Perché sta succedendo e come posso risolverlo?

+1

Si prega di mostrare un po 'di questi errori che si ricevono. –

+0

L'unica correzione è di non usare '/ WAll', purtroppo. – alain

+0

Non è possibile * "alzare gli errori" *. Gli errori sono errori e non si arriva a decidere cosa sia un errore e cosa no (unica eccezione: l'opzione * tratta gli avvertimenti come errori *). È possibile aumentare il livello * di avvertenza *. Se questo è ciò a cui ti riferisci, ti preghiamo di aggiornare la tua domanda. – IInspectable

risposta

11

Con Visual C++ è necessario utilizzare /W4, non /Wall che non è pratico. Se il livello di avviso 4 produce ancora insensibili, ad es. dalle intestazioni standard, quindi prendere in considerazione l'utilizzo del mio vecchio MSVC "no sillywarnings" header o un'estensione adeguata. Preferibilmente quindi tramite un'opzione di compilazione include forzata.

Per lavorare con Visual C++ nella riga di comando io in genere uso il seguente variabile d'ambiente:

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

Pare che ci sia ora soppressione automatica di avvertimenti da intestazioni di sistema, quindi non è un problema.


Si prega di notare che, mentre di serie il santo C++ non distingue tra i diversi tipi di diagnosi, come de facto compilatori C++ standard e linker distinguere tra

  • errori:
    Una diagnostica di errore significa che non viene prodotto alcun eseguibile (o file oggetto).

  • Avvertenze:
    un avvertimento mezzi diagnostici che qualcosa non probabile che sia sbagliato, o almeno era un po 'discutibile, ma il compilatore o linker o altro strumento effettuate nell'assumere si sapeva quello che stavi facendo.

    intestazioni

Rilevante MSVC-specifici è possibile forzare-includono (opzionale /FI), tra cui una maggiore versione aggiornata dei no sillywarnings intestazione:

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)