2016-05-30 10 views
6

Zaczynam uczyć się języka C++ i czytam, że zwiększenie poziomu ostrzeżenia jest dobrym pomysłem, aby zachować ostrożność podczas pisania kodu. Używam programu Visual Studio 2015 (wersja społecznościowa)Ostrzeżenie - Usunięto funkcję Inline z odwołaniem

Po otrzymaniu tego otrzymuję setki błędów (edycja: OSTRZEŻENIA traktowane jako błędy, przepraszam) nawet w podstawowych programach. Wszystko to pochodzi z nagłówka matematycznego, a oni mówią, że "nieodwoływana funkcja inline została usunięta". Wygląda na to, że każda metoda, której nie używam, powoduje ostrzeżenie.

Dlaczego tak się dzieje i jak mogę to naprawić?

+1

Proszę pokazać niektóre z tych błędów, które otrzymujesz. –

+0

Jedyną poprawką nie jest użycie '/ WAll', niestety. – alain

+0

Nie można * "podkręcić błędów" *. Błędy są błędami i nie decydują o tym, co jest błędem, a co nie (tylko wyjątek: * Traktuj ostrzeżenia jako błędy *). Możesz zwiększyć poziom * ostrzeżenia *. Jeśli o to ci chodzi, zaktualizuj swoje pytanie. – IInspectable

Odpowiedz

11

Z Visual C++ powinieneś używać /W4, a nie /Wall, co jest niepraktyczne. Jeśli poziom ostrzeżenia 4 nadal generuje niemądre ostrzeżenia, np. ze standardowych nagłówków, następnie rozważ użycie mojego starego MSVC "no sillywarnings" header lub odpowiedniego rozszerzenia tego. Najlepiej wtedy za pomocą opcji wymuszonego kompilatora włączającego.

Do pracy z Visual C++ w wierszu polecenia I generalnie wykorzystać następującą zmienną środowiskową:

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

Podobno jest teraz automatyczne stłumienie ostrzeżeń nagłówków systemowych, więc to nie jest problem.


Należy pamiętać, że podczas święta C średnia ++ nie rozróżnia różne rodzaje diagnostyki jako de facto standardowe ++ kompilatory i łączniki C odróżnić

  • Błędy:
    Diagnostyka błędu oznacza, że ​​nie powstaje plik wykonywalny (lub plik obiektowy).

  • Ostrzeżenia:
    ostrzeżeniem środki diagnostyczne, że coś może być nie tak, albo przynajmniej była nieco wątpliwa, ale kompilator lub linker lub inne narzędzie prowadzone przy założeniu, że nie wiedział, co robisz.


Stosowna MSVC specyficzne nagłówki można wymusić obejmują (opcja /FI), tym bardziej się do aktualnej wersji bez sillywarnings nagłówka:

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) 
Powiązane problemy