lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 0f1bc07 03/12: Split the check for canonical


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 0f1bc07 03/12: Split the check for canonical header guards in two parts
Date: Mon, 28 Jun 2021 18:44:27 -0400 (EDT)

branch: master
commit 0f1bc07737f2aac13d2103e04b901fd2688cff73
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Split the check for canonical header guards in two parts
    
    While Boost.Regex has no trouble with a regex containing ".*" and
    consuming the entire file, std::regex seems to implement support for "*"
    using recursion, resulting in horrible performance characteristics, and,
    even worse, crashing with stack overflow on big enough files (where big
    enough starts at just about ~30KiB already).
    
    Splitting the check in two also allows to give slightly more useful
    error messages in case it fails.
---
 test_coding_rules.cpp     | 9 +++++----
 test_coding_rules_test.sh | 8 ++++----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/test_coding_rules.cpp b/test_coding_rules.cpp
index 2dff4d1..7815898 100644
--- a/test_coding_rules.cpp
+++ b/test_coding_rules.cpp
@@ -782,13 +782,14 @@ void check_include_guards(file const& f)
         ,boost::regex(R"(\.hpp$)")
         ,"_hpp"
         );
-    std::string const guards =
+    std::string const guard_start =
             R"(\n#ifndef )"   + guard
         +   R"(\n#define )"   + guard + R"(\n)"
-        +   ".*"
-        +   R"(\n#endif // )" + guard + R"(\n+$)"
         ;
-    require(f, guards, "lacks canonical header guards.");
+    std::string const guard_end = R"(\n#endif // )" + guard + R"(\n+$)";
+
+    require(f, guard_start, "lacks start part of the canonical header guard.");
+    require(f, guard_end, "lacks end part of the canonical header guard.");
 }
 
 void check_inclusion_order(file const& f)
diff --git a/test_coding_rules_test.sh b/test_coding_rules_test.sh
index 601eb67..dca7142 100755
--- a/test_coding_rules_test.sh
+++ b/test_coding_rules_test.sh
@@ -409,10 +409,10 @@ File 'eraseme_cpp_003.cpp' should fuse '&' with type: 
'foo &bar(); // bar() is a
 File 'eraseme_cpp_003.cpp' should fuse '*' with type: 'int *x;     // x is a 
'pointer variable of type int'?'.
 File 'eraseme_cpp_004.cpp' should write 'const' after the type it modifies: 
'const T&'.
 File 'eraseme_cpp_004.cpp' should write 'const' after the type it modifies: 
'const std::string&'.
-File 'eraseme_hpp_001.hpp' lacks canonical header guards.
-File 'eraseme_hpp_002.hpp' lacks canonical header guards.
-File 'eraseme_hpp_003.hpp' lacks canonical header guards.
-File 'eraseme_hpp_004.hpp' lacks canonical header guards.
+File 'eraseme_hpp_001.hpp' lacks end part of the canonical header guard.
+File 'eraseme_hpp_002.hpp' lacks start part of the canonical header guard.
+File 'eraseme_hpp_003.hpp' lacks start part of the canonical header guard.
+File 'eraseme_hpp_004.hpp' lacks end part of the canonical header guard.
 File 'eraseme_hpp_005.hpp' must include 'config.hpp' first.
 File 'eraseme_hpp_006.hpp' must include 'config.hpp'.
 File 'eraseme_hpp_006.hpp' lacks line '#include "config.hpp"'.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]