[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master a28eba74 8/8: Forbid "_Forbidden" [273]
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master a28eba74 8/8: Forbid "_Forbidden" [273] |
Date: |
Thu, 19 May 2022 13:29:04 -0400 (EDT) |
branch: master
commit a28eba74f40a01e9fa2655ea00ccf2e75a3f07ef
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Forbid "_Forbidden" [273]
---
test_coding_rules.cpp | 33 ++++++++++++++++++---------------
test_coding_rules_test.sh | 1 +
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/test_coding_rules.cpp b/test_coding_rules.cpp
index 6cbd1f08..4726f706 100644
--- a/test_coding_rules.cpp
+++ b/test_coding_rules.cpp
@@ -579,7 +579,7 @@ void check_cxx(file const& f)
for(auto const& z : pcre::search_all(f.data(), r))
{
std::string s = z[0];
- static pcre::regex const include_guard(R"(# *ifndef
*[[:lower:]][_\d[:lower:]]*_hpp\W)");
+ static pcre::regex const include_guard(R"(# *ifndef
*[[:lower:]][_\d[:lower:]]*[_]hpp\W)");
if(!pcre::search(s, include_guard))
{
ltrim(s, "\n");
@@ -937,7 +937,9 @@ bool check_reserved_name_exception(std::string const& s)
,"__func__"
,"__has_include"
// Platform identification.
+ ,"_ISOC99_SOURCE"
,"_M_IX86"
+ ,"_M_IX86_FP"
,"_M_X64"
,"_X86_"
,"__X__"
@@ -989,7 +991,9 @@ bool check_reserved_name_exception(std::string const& s)
,"__MINGW64_VERSION_MAJOR"
,"__MINGW_H"
,"_fmode"
+ ,"_get_output_format"
// Compiler specific: glibc.
+ ,"_GLIBCXX_DEBUG"
,"_LIBC"
,"__BIG_ENDIAN"
,"__BYTE_ORDER"
@@ -1022,8 +1026,14 @@ bool check_reserved_name_exception(std::string const& s)
,"_O_WRONLY"
,"_PC_64"
,"_RC_NEAR"
+ ,"_doserrno"
,"_fileno"
,"_setmode"
+ // Poe.
+ ,"_bizarre_"
+ // GNU getopt.
+ ,"_OPTIONS_FIRST"
+ ,"_POSIX_OPTION_ORDER"
// Library specific.
,"D__WXDEBUG__" // Hapax legomenon.
,"__WXGTK__"
@@ -1046,33 +1056,26 @@ bool check_reserved_name_exception(std::string const& s)
/// The regex iterated for is deliberately overbroad. Measurement
/// shows that it is far more efficient to cast the net widely and
/// then filter the matches: there's a lot more sea than fish.
-///
-/// TODO ?? Also test '_[A-Za-z0-9]', e.g. thus:
-/// "(\\b\\w*__\\w*\\b)|(\\b\\_\\w+\\b)"
void check_reserved_names(file const& f)
{
- if
- ( f.phyloanalyze("^configure.ac$")
- || f.phyloanalyze("^test_coding_rules_test.sh$")
- )
- {
- return;
- }
-
- if(f.is_of_phylum(e_log))
+ if(!f.is_of_phylum(e_c_or_cxx))
{
return;
}
- static pcre::regex const r(R"((\b\w*__\w*\b))");
+ static pcre::regex const r(R"((\b\w*__\w*\b)|("*\b\_\w+\b"*))");
for(auto const& z : pcre::search_all(f.data(), r))
{
std::string const s = z[0];
static pcre::regex const not_all_underscore("[A-Za-z0-9]");
+ static pcre::regex const quoted_name(R"("_+[A-Za-z0-9]\w*")");
+ static pcre::regex const literal_operator(R"(""_[A-Za-z])");
if
( !check_reserved_name_exception(s)
- && pcre::search(s, not_all_underscore)
+ && pcre::search(s, not_all_underscore)
+ && !pcre::search(s, quoted_name)
+ && !pcre::search(s, literal_operator)
)
{
std::ostringstream oss;
diff --git a/test_coding_rules_test.sh b/test_coding_rules_test.sh
index 55e31db6..41105c5c 100755
--- a/test_coding_rules_test.sh
+++ b/test_coding_rules_test.sh
@@ -473,6 +473,7 @@ File 'eraseme_cpp_007.cpp' should have a space on both
sides of the colon follow
File 'eraseme_cpp_007.cpp' should have a space on both sides of the colon
following the for-range-declaration, instead of ': '.
File 'eraseme_cpp_007.cpp' for-range-declaration should deduce type rather
than specify 'int'.
File 'eraseme_cpp_007.cpp' for-range-declaration should use 'auto&' or 'auto
const&' instead of 'auto '.
+File 'eraseme_cpp_008.cpp' contains reserved name '_Forbidden'.
File 'eraseme_cpp_008.cpp' contains reserved name '__forbidden'.
File 'eraseme_hpp_001.hpp' lacks canonical closing header guard.
File 'eraseme_hpp_002.hpp' lacks canonical opening header guard.
- [lmi-commits] [lmi] master updated (041ca2fb -> a28eba74), Greg Chicares, 2022/05/19
- [lmi-commits] [lmi] master 3c412791 1/8: Allow certain reserved names, Greg Chicares, 2022/05/19
- [lmi-commits] [lmi] master 00d58837 3/8: Test forbiddance of some reserved names, Greg Chicares, 2022/05/19
- [lmi-commits] [lmi] master 1f4c7138 2/8: Allow 'test_coding_rules_test.sh' to contain reserved names, Greg Chicares, 2022/05/19
- [lmi-commits] [lmi] master 776827ee 4/8: Avoid typewriter-style citations, Greg Chicares, 2022/05/19
- [lmi-commits] [lmi] master 9c348d06 5/8: Avoid using _this_ style for emphasis, Greg Chicares, 2022/05/19
- [lmi-commits] [lmi] master 8ecde06f 6/8: Avoid reserved names in token pasting, Greg Chicares, 2022/05/19
- [lmi-commits] [lmi] master 15b60953 7/8: Avoid reserved names and anything resembling them, Greg Chicares, 2022/05/19
- [lmi-commits] [lmi] master a28eba74 8/8: Forbid "_Forbidden" [273],
Greg Chicares <=