[clang] [clang] Allow extra semicolons inside classes also in C++ pedantic mode. (PR #172209)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 15 00:23:24 PST 2025


================
@@ -205,27 +205,40 @@ void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, DeclSpec::TST TST) {
     ConsumeToken();
   }
 
+  if (Kind == ExtraSemiKind::AfterMemberFunctionDefinition &&
+      !HadMultipleSemis) {
+    // A single semicolon is valid after a member function definition.
+    Diag(StartLoc, diag::warn_extra_semi_after_mem_fn_def)
+        << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));
+    return;
+  }
+
   // C++11 allows extra semicolons at namespace scope, but not in any of the
   // other contexts.
-  if (Kind == ExtraSemiKind::OutsideFunction && getLangOpts().CPlusPlus) {
+  // DR 1693 and DR 3079 extend this to class scope as well.
+  if ((Kind == ExtraSemiKind::OutsideFunction ||
+       Kind == ExtraSemiKind::InsideStruct ||
+       Kind == ExtraSemiKind::AfterMemberFunctionDefinition) &&
+      getLangOpts().CPlusPlus) {
     if (getLangOpts().CPlusPlus11)
-      Diag(StartLoc, diag::warn_cxx98_compat_top_level_semi)
+      Diag(StartLoc, diag::warn_cxx98_compat_extra_semi)
+          << Kind
+          << DeclSpec::getSpecifierName(
+                 TST, Actions.getASTContext().getPrintingPolicy())
----------------
cor3ntin wrote:

Can we use `DiagCompat` here @Sirraide ? 

https://github.com/llvm/llvm-project/pull/172209


More information about the cfe-commits mailing list