The compiler is able to emit a warning for this. But all compilers don’t emit the same warning. Let’s take the example of the warning that warns you that you didn’t use one of the parameters of a function: void f(int a, int b) Let’s see how to do that and keep code expressive. Second, if you’re following the best practice of transforming warnings into errors, by activating the -Werror flag in gcc and clang for example, leaving a warning in is simply not an option.įortunately, C++ lets you block the emission of a specific warning for a portion of code. This doesn’t scale if there are several warnings you decide to leave, because at each build you’ll have to check them all to see if a new warning hasn’t popped up and needs to be checked. This warning will always remain here, and you’ll have to check that it’s the one you decided to leave in every time you compile the code. First, you will no longer have a clean build with no errors and no warnings. In such occasions, letting the warning in the compiler’s output has several drawbacks. In the vast majority of cases, the compiler has a good reason to emit them, and in the vast majority of cases, they point out to an oversight in your code.īut in a minority of cases, you may want to deliberately write code that triggers a warning. As explained in item 53 of Effective C++, you should “Pay attention to compiler warnings”.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |