[clang] Only emit -Wmicrosoft-goto in C++ mode (PR #138507)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 5 04:20:50 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Hans Wennborg (zmodem)
<details>
<summary>Changes</summary>
Follow-up to #<!-- -->138009 which added diagnostics for "jump past initialization" in C mode, in which case they're not an MS extension.
---
Full diff: https://github.com/llvm/llvm-project/pull/138507.diff
2 Files Affected:
- (modified) clang/lib/Sema/JumpDiagnostics.cpp (+2-1)
- (modified) clang/test/Sema/warn-jump-bypasses-init.c (+1)
``````````diff
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<unsigned, 10> ToScopesError;
SmallVector<unsigned, 10> 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/138507
More information about the cfe-commits
mailing list