From e6b4426780160c2d1e4fb0b3ae213c68435004c0 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Mon, 5 May 2025 13:15:55 +0200 Subject: [PATCH] Only emit -Wmicrosoft-goto in C++ mode Follow-up to #138009 which added diagnostics for "jump past initialization" in C mode, in which case they're not an MS extension. --- clang/lib/Sema/JumpDiagnostics.cpp | 3 ++- clang/test/Sema/warn-jump-bypasses-init.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp index 6d71b26801107..a852a950b47f4 100644 --- a/clang/lib/Sema/JumpDiagnostics.cpp +++ b/clang/lib/Sema/JumpDiagnostics.cpp @@ -998,7 +998,8 @@ void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc, SmallVector ToScopesError; SmallVector ToScopesWarning; for (unsigned I = ToScope; I != CommonScope; I = Scopes[I].ParentScope) { - if (S.getLangOpts().MSVCCompat && JumpDiagWarning != 0 && + if (S.getLangOpts().MSVCCompat && S.getLangOpts().CPlusPlus && + JumpDiagWarning != 0 && IsMicrosoftJumpWarning(JumpDiagError, Scopes[I].InDiag)) ToScopesWarning.push_back(I); else if (IsCXX98CompatWarning(S, Scopes[I].InDiag) || diff --git a/clang/test/Sema/warn-jump-bypasses-init.c b/clang/test/Sema/warn-jump-bypasses-init.c index a9604742bf50c..53f10722406cd 100644 --- a/clang/test/Sema/warn-jump-bypasses-init.c +++ b/clang/test/Sema/warn-jump-bypasses-init.c @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify=c,both -Wjump-bypasses-init %s // RUN: %clang_cc1 -fsyntax-only -verify=c,both -Wc++-compat %s // RUN: %clang_cc1 -fsyntax-only -verify=good %s +// RUN: %clang_cc1 -fsyntax-only -verify=good -fms-compatibility %s // RUN: %clang_cc1 -fsyntax-only -verify=cxx,both -x c++ %s // good-no-diagnostics