From f6ecadb7aea68fb322bfa1dfce703a24cbd1e395 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 10 Feb 2018 00:51:00 +0000 Subject: Renable -Wimplicit-fallthrough for PDFium. Didn't find any bugs, but also doesn't require much boilerplate. Bug: TODO Change-Id: I5f30183c55216f1333c79fcb46476d281720873e Reviewed-on: https://pdfium-review.googlesource.com/26210 Reviewed-by: Lei Zhang Commit-Queue: Nico Weber --- core/fxcrt/fx_extension.cpp | 3 +++ core/fxcrt/fx_fallthrough.h | 20 ++++++++++++++++++++ core/fxcrt/xml/cxml_parser.cpp | 3 +++ 3 files changed, 26 insertions(+) create mode 100644 core/fxcrt/fx_fallthrough.h (limited to 'core/fxcrt') diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index 62cf8a0e04..371f1b5211 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -6,6 +6,8 @@ #include "core/fxcrt/fx_extension.h" +#include "core/fxcrt/fx_fallthrough.h" + #include #include @@ -21,6 +23,7 @@ float FXSYS_wcstof(const wchar_t* pwsStr, int32_t iLength, int32_t* pUsedLen) { switch (pwsStr[iUsedLen]) { case '-': bNegtive = true; + FX_FALLTHROUGH; case '+': iUsedLen++; break; diff --git a/core/fxcrt/fx_fallthrough.h b/core/fxcrt/fx_fallthrough.h new file mode 100644 index 0000000000..5587ee2295 --- /dev/null +++ b/core/fxcrt/fx_fallthrough.h @@ -0,0 +1,20 @@ +// Copyright 2018 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CORE_FXCRT_FX_FALLTHROUGH_H_ +#define CORE_FXCRT_FX_FALLTHROUGH_H_ + +// When clang suggests inserting [[clang::fallthrough]], it first checks if +// it knows of a macro expanding to it, and if so suggests inserting the +// macro. This means that this macro must be used only in code internal +// to PDFium, so that PDFium's user code doesn't end up getting suggestions +// for FX_FALLTHROUGH instead of the user-specific fallthrough macro. +// So do not include this header in any of PDFium's public headers. +#if defined(__clang__) +#define FX_FALLTHROUGH [[clang::fallthrough]] +#else +#define FX_FALLTHROUGH +#endif + +#endif // CORE_FXCRT_FX_FALLTHROUGH_H_ diff --git a/core/fxcrt/xml/cxml_parser.cpp b/core/fxcrt/xml/cxml_parser.cpp index ae5fd6d0fc..64bb0ec530 100644 --- a/core/fxcrt/xml/cxml_parser.cpp +++ b/core/fxcrt/xml/cxml_parser.cpp @@ -14,6 +14,7 @@ #include "core/fxcrt/cfx_utf8decoder.h" #include "core/fxcrt/cfx_widetextbuf.h" #include "core/fxcrt/fx_extension.h" +#include "core/fxcrt/fx_fallthrough.h" #include "core/fxcrt/xml/cxml_content.h" #include "core/fxcrt/xml/cxml_element.h" #include "core/fxcrt/xml/cxml_parser.h" @@ -200,6 +201,7 @@ uint32_t CXML_Parser::GetCharRef() { break; } iState = 1; + FX_FALLTHROUGH; case 1: m_dwIndex++; if (ch == ';') { @@ -226,6 +228,7 @@ uint32_t CXML_Parser::GetCharRef() { break; } iState = 3; + FX_FALLTHROUGH; case 3: m_dwIndex++; if (ch == ';') { -- cgit v1.2.3