From ea3952d8a9e09f8702ae78b74fdda8046209779a Mon Sep 17 00:00:00 2001 From: Wim Leflere Date: Wed, 17 Feb 2016 13:59:22 +0100 Subject: [PATCH 1/3] Issue 89 - Warning on using namespace in header - Ignore Eclipse and PyDev project files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index fa8ad13..c11a148 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ htmlcov/ *.egg*/ .coverage .travis-solo/ +.project +.pydevproject From 43e3c82280de3fbb2d11a9a12dab3c0303512828 Mon Sep 17 00:00:00 2001 From: Wim Leflere Date: Wed, 17 Feb 2016 16:55:25 +0100 Subject: [PATCH 2/3] Issue 89 - Warning on using namespace in header - Add warning --- cpp/find_warnings.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cpp/find_warnings.py b/cpp/find_warnings.py index caea7de..a6f37cc 100644 --- a/cpp/find_warnings.py +++ b/cpp/find_warnings.py @@ -203,6 +203,14 @@ def _read_and_parse_includes(self): return included_files, forward_declarations + def _find_using_namespaces(self): + for node in self.ast_list: + if isinstance(node, ast.Using): + self._add_warning( + "'using namespace ...' should not be used in a header file" + ", ignoring rest of file", + node) + def _verify_include_files_used(self, file_uses, included_files): """Find all #include files that are unnecessary.""" for include_file, use in file_uses.items(): @@ -433,8 +441,10 @@ def _find_unused_warnings(self, included_files, forward_declarations, self._add_warning(msg, node) def _find_header_warnings(self): - included_files, forward_declarations = self._read_and_parse_includes() - self._find_unused_warnings(included_files, forward_declarations) + self._find_using_namespaces() + if(len(self.warnings) == 0): + included_files, forward_declarations = self._read_and_parse_includes() + self._find_unused_warnings(included_files, forward_declarations) def _find_public_function_warnings(self, node, name, primary_header, all_headers): From be158987393061521bf9a2b075eb233823951ca4 Mon Sep 17 00:00:00 2001 From: Wim Leflere Date: Wed, 17 Feb 2016 16:56:58 +0100 Subject: [PATCH 3/3] Issue 89 - Warning on using namespace in header - Add warning to expected output --- test/expected.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/expected.txt b/test/expected.txt index e4b2d6a..0a31b95 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -63,6 +63,7 @@ test/unused_static.cc:7: static data 'i' test/unused_static.cc:8: static data 'j' test/unused_static.cc:3: unused variable 'z' test/unused_static.cc:4: unused variable 'b' +test/using.h:8: 'using namespace ...' should not be used in a header file, ignoring rest of file test/with_main.cc:2: 'include.h' already #included on line 1 test/with_main.cc:3: 'include.h' already #included on line 1 test/with_main.cc:9: 'Foo' forward declaration not expected in source file