Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ htmlcov/
*.egg*/
.coverage
.travis-solo/
.project
.pydevproject
14 changes: 12 additions & 2 deletions cpp/find_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it would be better if self._find_using_namespaces() returned True if it finds a problem. That way you could do something like:

if not self._find_using_namespaces():
    included_files, forward_declarations = self._read_and_parse_includes()
    self._find_unused_warnings(included_files, forward_declarations)

The above doesn't rely on the self.warnings, which might be modified by other methods (at least in future implementations).

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):
Expand Down
1 change: 1 addition & 0 deletions test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down