summaryrefslogtreecommitdiffstats
path: root/docs/ReleaseNotes.rst
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2018-11-20 18:59:05 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2018-11-20 18:59:05 +0000
commit710518321bb5cae09e462db3c5eb50f2fc711e57 (patch)
tree6760b995203b5259eea454ac3b1b3ea68ad7d4ca /docs/ReleaseNotes.rst
parenta0372123a05b65ef80267122a7f33121026bdf81 (diff)
[clang][Parse] Diagnose useless null statements / empty init-statements
Summary: clang has `-Wextra-semi` (D43162), which is not dictated by the currently selected standard. While that is great, there is at least one more source of need-less semis - 'null statements'. Sometimes, they are needed: ``` for(int x = 0; continueToDoWork(x); x++) ; // Ugly code, but the semi is needed here. ``` But sometimes they are just there for no reason: ``` switch(X) { case 0: return -2345; case 5: return 0; default: return 42; }; // <- oops ;;;;;;;;;;; <- OOOOPS, still not diagnosed. Clearly this is junk. ``` Additionally: ``` if(; // <- empty init-statement true) ; switch (; // empty init-statement x) { ... } for (; // <- empty init-statement int y : S()) ; } As usual, things may or may not go sideways in the presence of macros. While evaluating this diag on my codebase of interest, it was unsurprisingly discovered that Google Test macros are *very* prone to this. And it seems many issues are deep within the GTest itself, not in the snippets passed from the codebase that uses GTest. So after some thought, i decided not do issue a diagnostic if the semi is within *any* macro, be it either from the normal header, or system header. Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=39111 | PR39111 ]] Reviewers: rsmith, aaron.ballman, efriedma Reviewed By: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D52695 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347339 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs/ReleaseNotes.rst')
-rw-r--r--docs/ReleaseNotes.rst57
1 files changed, 57 insertions, 0 deletions
diff --git a/docs/ReleaseNotes.rst b/docs/ReleaseNotes.rst
index 5e6dfdf1c1..ca95b7c780 100644
--- a/docs/ReleaseNotes.rst
+++ b/docs/ReleaseNotes.rst
@@ -55,6 +55,63 @@ Major New Features
Improvements to Clang's diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+- ``-Wextra-semi-stmt`` is a new diagnostic that diagnoses extra semicolons,
+ much like ``-Wextra-semi``. This new diagnostic diagnoses all *unnecessary*
+ null statements (expression statements without an expression), unless: the
+ semicolon directly follows a macro that was expanded to nothing or if the
+ semicolon is within the macro itself. This applies to macros defined in system
+ headers as well as user-defined macros.
+
+ .. code-block:: c++
+
+ #define MACRO(x) int x;
+ #define NULLMACRO(varname)
+
+ void test() {
+ ; // <- warning: ';' with no preceding expression is a null statement
+
+ while (true)
+ ; // OK, it is needed.
+
+ switch (my_enum) {
+ case E1:
+ // stuff
+ break;
+ case E2:
+ ; // OK, it is needed.
+ }
+
+ MACRO(v0;) // Extra semicolon, but within macro, so ignored.
+
+ MACRO(v1); // <- warning: ';' with no preceding expression is a null statement
+
+ NULLMACRO(v2); // ignored, NULLMACRO expanded to nothing.
+ }
+
+- ``-Wempty-init-stmt`` is a new diagnostic that diagnoses empty init-statements
+ of ``if``, ``switch``, ``range-based for``, unless: the semicolon directly
+ follows a macro that was expanded to nothing or if the semicolon is within the
+ macro itself (both macros from system headers, and normal macros). This
+ diagnostic is in the ``-Wextra-semi-stmt`` group and is enabled in
+ ``-Wextra``.
+
+ .. code-block:: c++
+
+ void test() {
+ if(; // <- warning: init-statement of 'if' is a null statement
+ true)
+ ;
+
+ switch (; // <- warning: init-statement of 'switch' is a null statement
+ x) {
+ ...
+ }
+
+ for (; // <- warning: init-statement of 'range-based for' is a null statement
+ int y : S())
+ ;
+ }
+
Non-comprehensive list of changes in this release
-------------------------------------------------