Skip to content

Commit

Permalink
cpplint.py: relax checks for "using namespace" declarations for impor…
Browse files Browse the repository at this point in the history
…ting custom literals.

For example, the standard library encourages "using namespace" like:

```
using namespace std::literals::chrono_literals (since C++14)
using namespace std::literals::complex_literals (since C++14)
using namespace std::literals::string_literals (since C++14)
using namespace std::literals::string_view_literals (since C++17)
```

so those shouldn't result in lint errors.

See https://en.cppreference.com/w/cpp/symbol_index/literals
  • Loading branch information
dconeybe committed Jan 10, 2025
1 parent e2031c7 commit 73e74cf
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions scripts/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@
'build/include_order',
'build/include_what_you_use',
'build/namespaces_headers',
'build/namespaces_literals',
'build/namespaces',
'build/printf_format',
'build/storage_class',
Expand Down Expand Up @@ -5352,15 +5351,10 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
'Did you mean "memset(%s, 0, %s)"?'
% (match.group(1), match.group(2)))

if Search(r'\busing namespace\b', line):
if Search(r'\bliterals\b', line):
error(filename, linenum, 'build/namespaces_literals', 5,
'Do not use namespace using-directives. '
'Use using-declarations instead.')
else:
error(filename, linenum, 'build/namespaces', 5,
'Do not use namespace using-directives. '
'Use using-declarations instead.')
if Search(r'\busing namespace\b', line) and not Search(r'\b::\w+_literals\b', line):
error(filename, linenum, 'build/namespaces', 5,
'Do not use namespace using-directives. '
'Use using-declarations instead.')

# Detect variable-length arrays.
match = Match(r'\s*(.+::)?(\w+) [a-z]\w*\[(.+)];', line)
Expand Down

0 comments on commit 73e74cf

Please sign in to comment.