[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 408173d: Enforce concinnity of for-range-decl
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 408173d: Enforce concinnity of for-range-declarations |
Date: |
Wed, 18 Jan 2017 10:00:07 +0000 (UTC) |
branch: master
commit 408173d2236e7e43e9260734c73d5a7ee7539b0d
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Enforce concinnity of for-range-declarations
For the rules and rationales, see:
http://lists.nongnu.org/archive/html/lmi/2017-01/msg00067.html
| for-range-declaration: ... decl-specifier-seq declarator
| the decl-specifier-seq shall be either 'auto' or 'auto const',
| whichever is more appropriate in context;
| the declarator shall include the '&' ref-qualifier
http://lists.nongnu.org/archive/html/lmi/2017-01/msg00082.html
| write spaces both before and after the colon
---
test_coding_rules.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/test_coding_rules.cpp b/test_coding_rules.cpp
index 7105a62..2d70a01 100644
--- a/test_coding_rules.cpp
+++ b/test_coding_rules.cpp
@@ -550,6 +550,69 @@ void check_cxx(file const& f)
}
}
}
+
+ // Tests above: C or C++. Tests below: C++ only.
+ if(!f.is_of_phylum(e_cxx))
+ {
+ return;
+ }
+
+ {
+ static std::string const p(R"(\bfor\b[^\n]+[^:\n]:[^:\n][^)\n]+\))");
+ static std::string const q(R"(\bfor\b\( *([:\w]+)( *[^ ]*) *\w+([ :]+))");
+ // This is "p && q || p", so to speak. If 'p' doesn't match, then
+ // ignore this occurrence. Else if 'q' matches, then diagnose the
+ // problem. Otherwise, match p again and show a diagnostic.
+ static boost::regex const r("(?=" + p + ")(?:" + q + ")|(" + p + ")");
+ boost::sregex_iterator i(f.data().begin(), f.data().end(), r);
+ boost::sregex_iterator const omega;
+ for(; i != omega; ++i)
+ {
+ boost::smatch const& z(*i);
+ if("" == z[1] && "" == z[2] && "" == z[3])
+ {
+ std::ostringstream oss;
+ oss
+ << "spurious or malformed for-range-declaration: '"
+ << z[0] << "'."
+ ;
+ complain(f, oss.str());
+ }
+ else
+ {
+ if("auto" != z[1])
+ {
+ std::ostringstream oss;
+ oss
+ << "for-range-declaration should"
+ << " deduce type rather than specify '"
+ << z[1] << "'."
+ ;
+ complain(f, oss.str());
+ }
+ if("&" != z[2] && " const&" != z[2])
+ {
+ std::ostringstream oss;
+ oss
+ << "for-range-declaration should"
+ << " use 'auto&' or 'auto const&' instead of '"
+ << z[1] << z[2] << "'."
+ ;
+ complain(f, oss.str());
+ }
+ if(" : " != z[3])
+ {
+ std::ostringstream oss;
+ oss
+ << "should have a space on both sides of the colon"
+ << " following the for-range-declaration, instead of '"
+ << z[3] << "'."
+ ;
+ complain(f, oss.str());
+ }
+ }
+ }
+ }
}
/// Check defect markers, which contain a doubled '!' or '?'.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [lmi] master 408173d: Enforce concinnity of for-range-declarations,
Greg Chicares <=