Skip to content

Commit c6ebc0b

Browse files
wilhuffCorrob
authored andcommitted
Add missing #include <ostream> (#2616)
* Add a lint check for ostream * Actaully #include <ostream> to undefined stream insertion operators at link time
1 parent a390058 commit c6ebc0b

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

Firestore/core/src/firebase/firestore/timestamp.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "Firestore/core/include/firebase/firestore/timestamp.h"
1818

19+
#include <ostream>
20+
1921
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
2022
#include "absl/strings/str_cat.h"
2123

Firestore/core/src/firebase/firestore/util/status.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "Firestore/core/src/firebase/firestore/util/status.h"
1818

19+
#include <ostream>
20+
1921
#include "Firestore/core/src/firebase/firestore/util/string_format.h"
2022
#include "absl/memory/memory.h"
2123

scripts/cpplint.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@
553553
# This is set by --headers flag.
554554
_hpp_headers = set(['h'])
555555

556+
# Source filename extensions
557+
_cpp_extensions = set(['cc', 'mm'])
558+
556559
# {str, bool}: a map from error categories to booleans which indicate if the
557560
# category should be suppressed for every line.
558561
_global_error_suppressions = {}
@@ -569,6 +572,15 @@ def ProcessHppHeadersOption(val):
569572
def IsHeaderExtension(file_extension):
570573
return file_extension in _hpp_headers
571574

575+
def IsSourceExtension(file_extension):
576+
return file_extension in _cpp_extensions
577+
578+
def IsSourceFilename(filename):
579+
global _cpp_extensions
580+
ext = os.path.splitext(filename)[-1].lower()
581+
ext = ext[1:] # leading dot
582+
return IsSourceExtension(ext)
583+
572584
def ParseNolintSuppressions(filename, raw_line, linenum, error):
573585
"""Updates the global list of line error-suppressions.
574586
@@ -4579,7 +4591,7 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
45794591
error(filename, linenum, 'build/include', 4,
45804592
'"%s" already included at %s:%s' %
45814593
(include, filename, duplicate_line))
4582-
elif (include.endswith('.cc') and
4594+
elif (IsSourceFilename(include) and
45834595
os.path.dirname(fileinfo.RepositoryName()) != os.path.dirname(include)):
45844596
error(filename, linenum, 'build/include', 4,
45854597
'Do not include .cc files from other packages')
@@ -5390,6 +5402,7 @@ def ExpectingFunctionArgs(clean_lines, linenum):
53905402
('<map>', ('map', 'multimap',)),
53915403
('<memory>', ('allocator', 'make_shared', 'make_unique', 'shared_ptr',
53925404
'unique_ptr', 'weak_ptr')),
5405+
('<ostream>', ('ostream',)),
53935406
('<queue>', ('queue', 'priority_queue',)),
53945407
('<set>', ('set', 'multiset',)),
53955408
('<stack>', ('stack',)),
@@ -5415,6 +5428,7 @@ def ExpectingFunctionArgs(clean_lines, linenum):
54155428
)
54165429

54175430
_RE_PATTERN_STRING = re.compile(r'\bstring\b')
5431+
_RE_PATTERN_OSTREAM = re.compile(r'\bostream\b')
54185432

54195433
_re_pattern_headers_maybe_templates = []
54205434
for _header, _templates in _HEADERS_MAYBE_TEMPLATES:
@@ -5553,6 +5567,14 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
55535567
if prefix.endswith('std::') or not prefix.endswith('::'):
55545568
required['<string>'] = (linenum, 'string')
55555569

5570+
# Ostream is special too -- also non-templatized
5571+
matched = _RE_PATTERN_OSTREAM.search(line)
5572+
if matched:
5573+
if IsSourceFilename(filename):
5574+
required['<ostream>'] = (linenum, 'ostream')
5575+
else:
5576+
required['<iosfwd>'] = (linenum, 'ostream')
5577+
55565578
for pattern, template, header in _re_pattern_headers_maybe_templates:
55575579
if pattern.search(line):
55585580
required[header] = (linenum, template)
@@ -5605,7 +5627,7 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
56055627
# didn't include it in the .h file.
56065628
# TODO(unknown): Do a better job of finding .h files so we are confident that
56075629
# not having the .h file means there isn't one.
5608-
if filename.endswith('.cc') and not header_found:
5630+
if IsSourceFilename(filename) and not header_found:
56095631
return
56105632

56115633
# All the lines have been processed, report the errors found.

0 commit comments

Comments
 (0)