compiler-warnings

Compile without generating output file in GCC

試著忘記壹切 提交于 2019-11-30 04:14:00
问题 $ gcc -c somefile.c compiles without linking and generates the corresponding somefile.o . Is it possible to compile files in gcc without generating any output file? I know there are other ways to achieve this but I'm curious on whether there is a flag just for going through the source code looking for errors/warnings. 回答1: You may like the -fsyntax-only option. It does not write anything on disk, just checks that the code is valid. You can check that it does not write anything on disk with

Treat Warnings as Errors has no effect

纵然是瞬间 提交于 2019-11-30 04:05:12
问题 In my project's settings in Visual Studio, I have set 'Treat warnings as errors' to 'All'. The Warning level is set to 4. I tested this by deliberately introducing code that violates CA1305, but it builds (and rebuilds) successfully, returning a Warning. What I expected was that the build would fail and an Error would be returned. Is my understanding wrong? 回答1: Code Analysis uses a different mechanism to treat warnings as errors. To have Code Analysis warnings treated as such, add a new Code

Capturing a variable in a Block when the Block is in the initializer

非 Y 不嫁゛ 提交于 2019-11-30 03:59:50
问题 Consider this: id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MyNotification object:nil queue:nil usingBlock:^(NSNotification *note) { [[NSNotificationCenter defaultCenter] removeObserver:observer name:MyNotification object:nil ]; // do other stuff here... } ]; I'm using this pattern to observe a notification once and then stop observing it. But LLVM tells me (under ARC) that Variable 'observer' is uninitialized when captured by block. How can I fix this, since the

Warning C4099: type name first seen using 'class' now seen using 'struct' (MS VS 2k8)

只愿长相守 提交于 2019-11-30 01:11:31
问题 Is this warning anything to worry about? I've read that it can cause erratic behaviour? It's an example I'm trying to compile, could someone explain to me why the author declares the object as a class but then typedef's it to a structure? Is it perfectly normal to do so if the class is POD? Thanks. 回答1: This warning appears when you have a one type declaration that contradicts another (one says "class", the other says "struct"). Given the one definition rule, all declarations except for at

Razor Compiler Warning/Errors - ASP.NET MVC 4

ぃ、小莉子 提交于 2019-11-30 00:35:31
I have an issue which seems to have been reported here: Need razor view engine auto-complete to work in a class library? My issue is the following Warning: G:\Accountable\Accountable\Views\LedgerUser\EditorTemplates\LedgerServiceViewModel.cshtml: ASP.NET runtime error: There is no build provider registered for the extension '.cshtml'. You can register one in the section in machine.config or web.config. Make sure is has a BuildProviderAppliesToAttribute attribute which includes the value 'Web' or 'All'. This issue is apparent in all my views. Sample images below. Now all posts and references

What warnings are included in Clang's -Wall and -Wextra?

隐身守侯 提交于 2019-11-30 00:31:53
问题 I've found Clang's documentation to be quite poor. I haven't been able to find much of a list of available Clang warning flags. I'm interested particularly in C/C++ warnings, but this is a bit of a general issue. GCC lists and describes warnings here, and also lists what is included in -Wall and -Wextra: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options What warning flags are included with Clang's -Wall and -Wextra? I can scour the Clang release notes for each version to

assert() with message

此生再无相见时 提交于 2019-11-29 22:12:40
I saw somewhere assert used with a message in the following way: assert(("message", condition)); This seems to work great, except that gcc throws the following warning: warning: left-hand operand of comma expression has no effect How can I stop the warning? Use -Wno-unused-value to stop the warning; (the option -Wall includes -Wunused-value ). I think even better is to use another method, like assert(condition && "message"); bugfeeder Try: #define assert__(x) for ( ; !(x) ; assert(x) ) use as such: assert__(x) { printf("assertion will fail\n"); } Will execute the block only when assert fails.

C++ Force compile-time error/warning on implicit fall-through in switch

跟風遠走 提交于 2019-11-29 22:04:30
switch statements can be super useful, but lead to a common bug where a programmer forgot a break statement: switch(val) { case 0: foo(); break; case 1: bar(); // oops case 2: baz(); break; default: roomba(); } You won't get a warning obviously since sometimes fall-through is explicitly desired. Good coding style suggests to comment when your fall-through is deliberate, but sometimes that is insufficient. I'm pretty sure the answer to this question is no, but: is there any way currently (or proposed in the future) to be able to ask the compiler to throw an error (or at least a warning!) if

Conditional references in .NET project, possible to get rid of warning?

六月ゝ 毕业季﹏ 提交于 2019-11-29 21:36:58
I have two references to a SQLite assembly, one for 32-bit and one for 64-bit, which looks like this (this is a test project to try to get rid of the warning, don't get hung up on the paths): <Reference Condition=" '$(Platform)' == 'x64' " Include="System.Data.SQLite, Version=1.0.61.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64"> <SpecificVersion>True</SpecificVersion> <HintPath>..\..\LVK Libraries\SQLite3\version_1.0.65.0\64-bit\System.Data.SQLite.DLL</HintPath> </Reference> <Reference Condition=" '$(Platform)' == 'x86' " Include="System.Data.SQLite, Version

How do I get rid of “[some event] never used” compiler warnings in Visual Studio?

懵懂的女人 提交于 2019-11-29 21:10:19
For example, I get this compiler warning, The event 'Company.SomeControl.SearchClick' is never used. But I know that it's used because commenting it out throws me like 20 new warnings of XAML pages that are trying to use this event! What gives? Is there a trick to get rid of this warning? This appears to be warning 67 and can thus be suppressed with: #pragma warning disable 67 Don't forget to restore it as soon as possible (after the event declaration) with: #pragma warning restore 67 However, I'd check again and make sure you're raising the event somewhere, not just subscribing to it. The