From b2eec586c83c46610a40bfb3c8412853d6c2cd8b Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Thu, 18 Oct 2018 20:06:40 +0000 Subject: [clang-tidy] Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4) Summary: Detects when the integral literal or floating point (decimal or hexadecimal) literal has non-uppercase suffix, and suggests to make the suffix uppercase, with fix-it. All valid combinations of suffixes are supported. ``` auto x = 1; // OK, no suffix. auto x = 1u; // warning: integer literal suffix 'u' is not upper-case auto x = 1U; // OK, suffix is uppercase. ... ``` References: * [[ https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152241 | CERT DCL16-C ]] * MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a literal suffix * MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52670 llvm-svn: 344755 --- .../readability/IdentifierNamingCheck.cpp | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp') diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp index 1d1168179cd..fb3c02e1750 100644 --- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp @@ -9,6 +9,7 @@ #include "IdentifierNamingCheck.h" +#include "../utils/ASTUtils.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/PPCallbacks.h" @@ -681,25 +682,7 @@ static void addUsage(IdentifierNamingCheck::NamingCheckFailureMap &Failures, if (!Failure.ShouldFix) return; - // Check if the range is entirely contained within a macro argument. - SourceLocation MacroArgExpansionStartForRangeBegin; - SourceLocation MacroArgExpansionStartForRangeEnd; - bool RangeIsEntirelyWithinMacroArgument = - SourceMgr && - SourceMgr->isMacroArgExpansion(Range.getBegin(), - &MacroArgExpansionStartForRangeBegin) && - SourceMgr->isMacroArgExpansion(Range.getEnd(), - &MacroArgExpansionStartForRangeEnd) && - MacroArgExpansionStartForRangeBegin == MacroArgExpansionStartForRangeEnd; - - // Check if the range contains any locations from a macro expansion. - bool RangeContainsMacroExpansion = RangeIsEntirelyWithinMacroArgument || - Range.getBegin().isMacroID() || - Range.getEnd().isMacroID(); - - bool RangeCanBeFixed = - RangeIsEntirelyWithinMacroArgument || !RangeContainsMacroExpansion; - Failure.ShouldFix = RangeCanBeFixed; + Failure.ShouldFix = utils::rangeCanBeFixed(Range, SourceMgr); } /// Convenience method when the usage to be added is a NamedDecl -- cgit v1.2.3