summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2018-10-18 20:06:40 +0000
committerRoman Lebedev <lebedev.ri@gmail.com>2018-10-18 20:06:40 +0000
commitb2eec586c83c46610a40bfb3c8412853d6c2cd8b (patch)
tree116579ec70ad3da18ce16e50c082f2a98dfb59fa /clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
parent87b6725c0e01cd422cc551835bea48cd58a94093 (diff)
downloadbcm5719-llvm-b2eec586c83c46610a40bfb3c8412853d6c2cd8b.tar.gz
bcm5719-llvm-b2eec586c83c46610a40bfb3c8412853d6c2cd8b.zip
[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
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp21
1 files changed, 2 insertions, 19 deletions
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
OpenPOWER on IntegriCloud