-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Replace #include guards with #pragma once #9069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Convince me why we shouldn't just switch everything over to |
Yeah, that was my other thought. But it's not standardised. I haven't tried to look into which compilers do or don't support it. |
Every compiler supports it on platforms we support. The only hold out was GCC prior to version 3.4 which is ancient. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #9069 +/- ##
===========================================
+ Coverage 63.74% 64.83% +1.08%
===========================================
Files 362 342 -20
Lines 44733 44392 -341
===========================================
+ Hits 28515 28778 +263
+ Misses 16218 15614 -604 ☔ View full report in Codecov by Sentry. |
I think most people would expect include guards and its what IDEs tend to auto generate. Besides that I don't really care what we use. Consistency would be nice. |
I prefer @c4rlo do you mind making that switch? |
Bumping this |
I can have another look at this, yes. Happy to go with |
Updated to |
Cool script! |
I used the following script to do this: #!/usr/bin/python import pathlib import re def replace(match, path, is_found): is_found[0] = True begin_newline = match.group(1) body = match.group(2) print(f"{path}: fixing") num_end_newlines = 0 for c in reversed(body): if c == "\n": num_end_newlines += 1 else: break if num_end_newlines > 1: body = body[:(1-num_end_newlines)] return (f"{begin_newline}#pragma once\n{body}") def process(path): content = path.read_text() if re.search(r"^#pragma once", content, flags=re.MULTILINE): print(f"{path}: ok") return is_found = [False] processed = re.sub( r"(^|\n)#ifndef .+?\n#define .+?\n(.*\n)#endif.+?\n?$", lambda m: replace(m, path, is_found), content, count=1, flags=re.DOTALL, ) if not is_found[0]: print(f"{path}: missing") else: path.write_text(processed) def relevant_files(): yield from pathlib.Path("src").walk() yield from pathlib.Path("tests").walk() for dirpath, dirnames, filenames in relevant_files(): if str(dirpath) == "src": dirnames.remove("thirdparty") for name in filenames: path = dirpath / name if path.suffix in (".h", ".h.cmake") and str(path) != "src/streams/qtiocompressor.h": process(path)
cf417e0
to
0ea6e7b
Compare
Make the names of#include
guards consistent across the project (with a special category forsrc/fdosecrets/*/*.h
based on prevailing usage). I have left out headers that clearly originate from other projects.Also make the format of the comment after the#endif
consistent.Remove one case of#pragma once
, replacing it with an#include
guard.Per discussion below, this PR now replaces
#include
guards with#pragma once
. This was done using the following script:Testing strategy
TeamCity
Type of change