[PATCH] D43162: [Parser] (C++) Make -Wextra-semi slightly more useful

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 14 12:34:15 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL327558: [Parser] (C++) Make -Wextra-semi slightly more useful (authored by lebedevri, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43162?vs=136503&id=138439#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43162

Files:
  cfe/trunk/include/clang/Basic/DiagnosticGroups.td
  cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
  cfe/trunk/test/Parser/cxx-extra-semi.cpp
  cfe/trunk/test/SemaCXX/extra-semi.cpp


Index: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
@@ -39,7 +39,7 @@
   InGroup<DiagGroup<"empty-translation-unit">>;
 def warn_cxx98_compat_top_level_semi : Warning<
   "extra ';' outside of a function is incompatible with C++98">,
-  InGroup<CXX98CompatPedantic>, DefaultIgnore;
+  InGroup<CXX98CompatExtraSemi>, DefaultIgnore;
 def ext_extra_semi : Extension<
   "extra ';' %select{"
   "outside of a function|"
Index: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td
@@ -151,8 +151,10 @@
 def GNUEmptyInitializer : DiagGroup<"gnu-empty-initializer">;
 def GNUEmptyStruct : DiagGroup<"gnu-empty-struct">;
 def ExtraTokens : DiagGroup<"extra-tokens">;
+def CXX98CompatExtraSemi : DiagGroup<"c++98-compat-extra-semi">;
 def CXX11ExtraSemi : DiagGroup<"c++11-extra-semi">;
-def ExtraSemi : DiagGroup<"extra-semi", [CXX11ExtraSemi]>;
+def ExtraSemi : DiagGroup<"extra-semi", [CXX98CompatExtraSemi,
+                                         CXX11ExtraSemi]>;
 
 def GNUFlexibleArrayInitializer : DiagGroup<"gnu-flexible-array-initializer">;
 def GNUFlexibleArrayUnionMember : DiagGroup<"gnu-flexible-array-union-member">;
@@ -196,6 +198,7 @@
 def CXX98CompatPedantic : DiagGroup<"c++98-compat-pedantic",
                                     [CXX98Compat,
                                      CXX98CompatBindToTemporaryCopy,
+                                     CXX98CompatExtraSemi,
                                      CXXPre14CompatPedantic,
                                      CXXPre17CompatPedantic,
                                      CXXPre2aCompatPedantic]>;
Index: cfe/trunk/test/SemaCXX/extra-semi.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/extra-semi.cpp
+++ cfe/trunk/test/SemaCXX/extra-semi.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -verify -std=c++98 -Wextra-semi %s
+// RUN: %clang_cc1 -verify -std=c++03 -Wextra-semi %s
+// RUN: %clang_cc1 -verify -std=c++11 -Wextra-semi %s
+// RUN: %clang_cc1 -verify -std=c++17 -Wextra-semi %s
+// RUN: %clang_cc1 -verify -std=c++2a -Wextra-semi %s
+// RUN: %clang_cc1 -verify -Weverything -Wno-c++98-compat %s
+// RUN: %clang_cc1 -verify -Weverything -Wno-c++98-compat-pedantic -Wc++98-compat-extra-semi %s
+
+// Last RUN line checks that c++98-compat-extra-semi can still be re-enabled.
+
+void F();
+
+void F(){}
+;
+#if __cplusplus < 201103L
+// expected-warning at -2{{extra ';' outside of a function is a C++11 extension}}
+#else
+// expected-warning at -4{{extra ';' outside of a function is incompatible with C++98}}
+#endif
+
+namespace ns {
+class C {
+  void F() const;
+};
+}
+; // expected-warning {{extra ';' outside of a function is}}
+
+void ns::C::F() const {}
+; // expected-warning {{extra ';' outside of a function is}}
Index: cfe/trunk/test/Parser/cxx-extra-semi.cpp
===================================================================
--- cfe/trunk/test/Parser/cxx-extra-semi.cpp
+++ cfe/trunk/test/Parser/cxx-extra-semi.cpp
@@ -38,4 +38,7 @@
 #if __cplusplus < 201103L
 // expected-warning at -3{{extra ';' outside of a function is a C++11 extension}}
 // expected-warning at -3{{extra ';' outside of a function is a C++11 extension}}
+#elif !defined(PEDANTIC)
+// expected-warning at -6{{extra ';' outside of a function is incompatible with C++98}}
+// expected-warning at -6{{extra ';' outside of a function is incompatible with C++98}}
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43162.138439.patch
Type: text/x-patch
Size: 3733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180314/0454bf86/attachment.bin>


More information about the cfe-commits mailing list