From 15da29c682124d9e7dae452ded26ae78cc3c0e8d Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 10 Nov 2012 01:47:40 +0000 Subject: [PATCH] Disable -Wimplicit-fallthrough when not using C++. The rationale is that there is no good workflow to silence the warning for specific cases, other than using pragmas. This is because the attribute to decorate an explicit fall through is only available in C++11. By that argument, this should probably also be disabled unless one is using C++11, but apparently there is an explicit test case for this warning when using C++98. This will require further discussion on cfe-commits. Fixes: llvm-svn: 167655 --- clang/lib/Sema/AnalysisBasedWarnings.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index a20817f..5c21ea4 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -818,6 +818,19 @@ namespace { static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC, bool PerFunction) { + // Only perform this analysis when using C++. There is no good workflow + // for this warning when using straight C. There is no good way to silence + // the warning (no attribute is available) unless we are using C++11's support + // for generalized attributes. Once could use pragmas to silence the warning, + // but as a general solution that is gross and not in the spirit of this + // warning. + // + // NOTE: this argument also applies to C++ code not using C++11, as the + // generalized attributes are not available in earlier C++ dialects. + // This will require some discussion. + if (!AC.getASTContext().getLangOpts().CPlusPlus) + return; + FallthroughMapper FM(S); FM.TraverseStmt(AC.getBody()); -- 2.7.4