Skip to content

Commit 80da3c1

Browse files
IWYU: treat stdio.h the same way as cstdio (cpplint#319)
Fixes cpplint#302 --------- Co-authored-by: Christian Clauss <[email protected]>
1 parent 3af0cd8 commit 80da3c1

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Changelog
88
Yet another overdue... hotfix. Sorry this took so long.
99

1010
* The false positive for indented function parameters in namespaces was eradicated.
11+
* build/include-what-you-use now recognizes c-style headers, such as <stdio.h> for symbols from <cstdio>. (https://github.com/cpplint/cpplint/pull/306)
1112

1213
2.0 (2024-10-06)
1314
================

cpplint.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6226,12 +6226,15 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
62266226
for item in sublist])
62276227

62286228
# All the lines have been processed, report the errors found.
6229-
for required_header_unstripped in sorted(required, key=required.__getitem__):
6230-
template = required[required_header_unstripped][1]
6231-
if required_header_unstripped.strip('<>"') not in include_dict:
6232-
error(filename, required[required_header_unstripped][0],
6229+
for header in sorted(required, key=required.__getitem__):
6230+
template = required[header][1]
6231+
header_stripped = header.strip('<>"')
6232+
if (header_stripped not in include_dict
6233+
and not (header_stripped[0] == 'c'
6234+
and (header_stripped[1:] + '.h') in include_dict)):
6235+
error(filename, required[header][0],
62336236
'build/include_what_you_use', 4,
6234-
'Add #include ' + required_header_unstripped + ' for ' + template)
6237+
'Add #include ' + header + ' for ' + template)
62356238

62366239

62376240
_RE_PATTERN_EXPLICIT_MAKEPAIR = re.compile(r'\bmake_pair\s*<')

cpplint_unittest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,9 @@ def testIncludeWhatYouUse(self):
11231123
self.TestIncludeWhatYouUse(
11241124
'printf("hello world");',
11251125
'Add #include <cstdio> for printf [build/include_what_you_use] [4]')
1126+
self.TestIncludeWhatYouUse(
1127+
"""#include <stdio.h>
1128+
printf("hello world");""", '') # Avoid false positives w/ c-style include
11261129
self.TestIncludeWhatYouUse(
11271130
'void a(const string &foobar);',
11281131
'Add #include <string> for string [build/include_what_you_use] [4]')

samples/vlc-sample/simple.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ src/*
44
Done processing src/libvlc.c
55
Done processing src/libvlc.h
66
Done processing src/missing.c
7-
Total errors found: 602
7+
Total errors found: 601
88

99
src/libvlc.c:41: Found C system header after other header. Should be: libvlc.h, c system, c++ system, other. [build/include_order] [4]
1010
src/libvlc.c:47: Found C system header after other header. Should be: libvlc.h, c system, c++ system, other. [build/include_order] [4]
@@ -367,7 +367,6 @@ src/libvlc.c:627: Missing space before ( in if( [whitespace/parens] [5]
367367
src/libvlc.c:629: Extra space after ( in function call [whitespace/parens] [4]
368368
src/libvlc.c:629: Extra space before ) [whitespace/parens] [2]
369369
src/libvlc.c:640: { should almost always be at the end of the previous line [whitespace/braces] [4]
370-
src/libvlc.c:223: Add #include <cstdio> for fclose [build/include_what_you_use] [4]
371370
src/libvlc.h:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_VLC_SAMPLE_SRC_LIBVLC_H_ [build/header_guard] [5]
372371
src/libvlc.h:34: Extra space before ( in function call [whitespace/parens] [4]
373372
src/libvlc.h:35: Extra space before ( in function call [whitespace/parens] [4]

0 commit comments

Comments
 (0)