From c2b100227daf8bcb541b527c7b17aa540ea64b1d Mon Sep 17 00:00:00 2001 From: granddaifuku Date: Wed, 2 Nov 2022 21:30:48 +0900 Subject: [PATCH 1/2] fix: allow blank lines and comments befor the inlcude guard --- onlinejudge_verify/languages/cplusplus_bundle.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/onlinejudge_verify/languages/cplusplus_bundle.py b/onlinejudge_verify/languages/cplusplus_bundle.py index 159c16ad..2c27b719 100644 --- a/onlinejudge_verify/languages/cplusplus_bundle.py +++ b/onlinejudge_verify/languages/cplusplus_bundle.py @@ -346,7 +346,11 @@ def update(self, path: pathlib.Path) -> None: continue if uncommented_line: - non_guard_line_found = True + if not non_guard_line_found and uncommented_line == b"\n": + # include guard の前がコメントまたは空行の場合は non_guard_line_found を True にしない + pass + else: + non_guard_line_found = True if include_guard_macro is not None and not include_guard_define_found: # 先頭に #ifndef が見付かっても #define が続かないならそれは include guard ではない include_guard_macro = None From 1ae85d3f84fd1e66d5d67483e9c36e2fa289e348 Mon Sep 17 00:00:00 2001 From: granddaifuku Date: Wed, 2 Nov 2022 21:38:11 +0900 Subject: [PATCH 2/2] fix: change the error message and the comment --- onlinejudge_verify/languages/cplusplus_bundle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onlinejudge_verify/languages/cplusplus_bundle.py b/onlinejudge_verify/languages/cplusplus_bundle.py index 2c27b719..cc483883 100644 --- a/onlinejudge_verify/languages/cplusplus_bundle.py +++ b/onlinejudge_verify/languages/cplusplus_bundle.py @@ -308,8 +308,8 @@ def update(self, path: pathlib.Path) -> None: if re.match(rb'\s*#\s*pragma\s+once\s*', line): # #pragma once は comment 扱いで消されてしまう logger.debug('%s: line %s: #pragma once', str(path), i + 1) if non_guard_line_found: - # 先頭以外で #pragma once されてた場合は諦める - raise BundleErrorAt(path, i + 1, "#pragma once found in a non-first line") + # #pragma once の前にコードが書かれていた場合に落とす + raise BundleErrorAt(path, i + 1, "found codes before #pragma once") if include_guard_macro is not None: raise BundleErrorAt(path, i + 1, "#pragma once found in an include guard with #ifndef") if path.resolve() in self.pragma_once: