-
-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add warning categories #5592
Add warning categories #5592
Conversation
This allows centralized filtering of which warning categories are enabled/disabled.
…rror, -Wxxx, and -Wno-xxx.
…ors with -w. (went unnoticed because the toHash() warning was never tested)
Includes testing of new warning commandline options.
|
Note that the CyberShadow/DAutoTest fails because of compilation with |
|
I am in favor of the changes in this PR, I can't comment on the implementation details however. Because this is such a large change, I would suggest posting something about this on the news group to solicit more opinions. |
|
I'm afraid what this does is balkanize D into multiple languages. It complicates the compiler, the spec, tutorials, and is something we'll have to support for the foreseeable future. It is not worth it. I know you've put a lot of time into this, and I'm sorry about that. Perhaps in the future a DIP would be worthwhile first to see if the idea has fertile ground. |
|
People almost never reply to DIPs seriously though. This at least elicited a definitive response from you :) |
|
@WalterBright (obviously a very disappointing response) I don't see how this complicates the compiler so much. |
|
I think the issue here is that such a switch affects not only the code it is meant to affect, but also all included modules from all included libraries. Some libraries may begin requiring that you turn some warnings off, thus complicating the build process for users of that library. Perhaps a more reasonable approach would be pragmas which disable some warnings locally, and have the scope of at most one module. |
I understand, I don't like seeing work go to waste. That's why I suggested in the future finding support for an idea beforehand.
To start with, 400 lines of changes. And it opens the door to this style, so I'd expect a bunch more coming.
Somebody has to document this stuff, explain it, determine best practice, etc. On a more global level, warnings are a failure of language design. Switch selectable language behavior is just a bad idea. I know that we have some already, but every one of them is symptomatic of failure. |
Instead of pragmas, I'd prefer there be ways of writing the code to avoid the warnings. |
Any ideas about the unreachable code warning in templated code? There is currently a proposal to remove that warning entirely (to which I'm opposed): #5229 |
Pretty much all warnings are not documented at the moment (yet they were added, and a few are not tested either). |
Perhaps it indicates a failure of language design, but that's what D is then and users have to deal with it in some way. Clang has some very nice warnings that involve coding style, that apply to D aswell. For example,
I am pretty certain that these two examples are not going to be resolved by changing the D language. In such cases, warnings help early prevention of bugs (imho). Of course this is debatable, therefore they are made optional. Edit: Thanks @CyberShadow for the correction about |
It's not clear from your message, but in case you're not aware, D has the same warnings, which are - as you said - resolved by changing the code a bit (adding parentheses, or adding an explicit "== true"). This is what @WalterBright meant by "writing the code to avoid the warnings".
With warnings-as-errors, it is no longer a diagnostic, but a rule of what is allowed and what isn't - hence, a "different language". |
Is not exactly true: the first example is not a warning in DMD, and the second example is an error in DMD. |
That's surprising, it probably should be.
We can't introduce that as an error right away, as that would break code. It could be introduced via a deprecation cycle.
That's a poor excuse for the problems that fragmentation brings with it. I agree with @WalterBright here. |
|
Cybershadow has it right:
For the "statement not reachable" warning (DMD 14835), Phobos itself would eventually require disabling the warning. I don't think that's a road any of us really wants to go down; there has to be a better solution. |
|
One could treat code in system headers different from user code (like clang does). |
How is that implemented? Not by locally disabling certain warnings using pragmas? |
|
http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-in-system-headers I will no longer maintain this PR. The PR is a solution to a current problem, with no other current solution, but to me it is clear you guys don't want this. Perhaps you can use parts of it. At least you may want to apply the bug fix. |
Oh, I misunderstood what you meant by system headers (I thought you meant the headers supplied with the compiler, not the system). That is not a problem that D has, since DMD does not have a necessity to be compatible with some pre-existing system headers that were written before it existed. This is a poor parallel to Phobos, of course, since as we are in control of Phobos as much as we are in control of the compiler, we would just change Phobos instead of introducing compiler switches.
Do pragmas to disable the warnings locally not solve the problem you have? |
I did mean that :) Afaik, "system headers" includes the C++stdlib headers.
Yep, I thought so too.
Yes pragmas would work. But I am discouraged from implementing it. This PR could be a first step if someone wants to take it up. |
I'm curious which warning is causing you so much grief. |
|
@WalterBright: If I'm not mistaken, this is the forum discussion, which links to this original thread. The issue is with "statement not reachable" in generic code, which, as @tsbockman points out, will get worse if we improve VRP. |
|
Thank you. I replied in the original thread. |
This PR splits warnings into categories, which can then be disabled/enabled to suit the user. For example the "statement not reachable" warning is very hard/ugly to work around in generic code, which means the user cannot compile with warnings enabled (warning spam), nor with warnings=errors. With this PR, the user could do
dmd -w -Wno-not-reachable, enabling all warnings except the not-reachable warning category.The dlang.org Warning page says:
"Most have generated some spirited debate as to whether it should be a warning, an error, and what the correct way to write D code in these situations should be. Since no consensus emerged, they appear as optional warnings, with alternatives on how to write correct code."
This PR makes warnings individually optional.
New commandline options are added, all starting with capital W:
-W...The behavior of
-wand-wiis unchanged.-Werror(warnings=errors, without enabling all warning categories)-W...andWno-...where a category name must be inserted on the dots.The category name is output at the end of the warning text (like clang does).
A warning can be put into more than one category, although at the moment all warnings belong to a single category.
Later options overwrite earlier options.
Examples:
-w, as before.-wi -Werror==-w-wi -Wno-conversion, will not warn on int += float-Wconversion, will only warn on int += float-Wno-conversion -Wconversion, will only warn on int += float-Wconversion -Wno-conversion, will not warn at all-Werror -Wconversion, will only warn on int += float and will error on that warningSome PR details:
errors.dto the new filewarnings.d-w(notably, the previously untestedtoHash()warning).