Skip to content
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

Fix pure cpp1 header file generated using -import-std #1319

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MatthieuHernandez
Copy link
Contributor

@MatthieuHernandez MatthieuHernandez commented Oct 17, 2024

I've noticed that if I execute cppfront.exe with the -import-std option on a .h file that doesn't contain any cpp2 code, then an #endif will be missing at the end of the file. See #1320 for more info.

⚠️ I haven't added any test because I didn't see any tests with .h files.

@JohelEGP

This comment was marked as resolved.

@gregmarr
Copy link
Contributor

A source without Cpp2 should be pass-through
(i.e., the Cpp2 source and the generated Cpp1 source should compare equal).

Unless you specify the flag to either import or include the standard library, then it adds extra stuff.

cppfront/source/to_cpp1.h

Lines 1298 to 1305 in 68b716a

// Only emit extra lines if we actually have Cpp2, because
// we want Cpp1-only files to pass through with zero changes
// (unless the user requested import/include of std)
if (
source.has_cpp2()
|| flag_import_std
|| flag_include_std
)

source/to_cpp1.h Outdated
@@ -1497,6 +1497,13 @@ class cppfront
//
if (!source.has_cpp2()) {
assert(ret.cpp2_lines == 0);
if (
cpp1_filename.back() == 'h'
&& flag_import_std
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(flag_import_std || flag_include_std) to match

cppfront/source/to_cpp1.h

Lines 1301 to 1305 in 68b716a

if (
source.has_cpp2()
|| flag_import_std
|| flag_include_std
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I force-pushed with your suggestion. Thanks 😊

@MatthieuHernandez MatthieuHernandez force-pushed the Fix_pure1_with_import_std branch from df266a6 to ed1fa67 Compare October 17, 2024 20:54
@hsutter
Copy link
Owner

hsutter commented Oct 31, 2024

Thanks for your pull request! It looks like this may be your first contribution to cppfront. I've emailed you the Contributor License Agreement (CLA), and once it's completed I can look at your pull request. Thanks again for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants