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

[BUG] cpp1 module declaration must be at beginning of generated .cpp file #1358

Open
abuehl opened this issue Jan 26, 2025 · 4 comments
Open
Labels
bug Something isn't working

Comments

@abuehl
Copy link

abuehl commented Jan 26, 2025

If the (mixed) .cpp2 input-file begins with a C++20 module declaration, e.g.

module foo;

the generated .cpp file is not valid C++20.

The file begins with various #includes and declarations, followed by the invalidly placed module declaration.

Also, #include's should be placed in the global module fragment.

@abuehl abuehl added the bug Something isn't working label Jan 26, 2025
@threeifbyair
Copy link

IMHO, I don't recommend using mainline cppfront if you're going to make significant use of modules. You're much better off using Johel's branch that has decent module support (https://github.com/JohelEGP/cppfront, branch cpp_modules). I did most of Advent of Code 2024 with that (https://github.com/threeifbyair/advent2024) and although it wasn't perfect, it did work.

@abuehl
Copy link
Author

abuehl commented Jan 28, 2025

Thanks for the pointer, I will try that. We have switched to C++ modules in a ~100 KLOC project using C++20 (MSVC on Windows).

@abuehl
Copy link
Author

abuehl commented Jan 28, 2025

I have read the rationale of Herb for closing #569 in 2023, but cppfront is currently producing wrong cpp1 code when a mixed syntax input .cpp2 file contains the module keyword. This is a showstopper for us.

As long as cppfront accepts mixed input I think it should at least correctly treat valid cpp1 code that is mixed with cpp2 code.

If/when cppfront should accept the module keyword in cpp2 syntax is a different thing.

@abuehl
Copy link
Author

abuehl commented Jan 28, 2025

IMHO, I don't recommend using mainline cppfront if you're going to make significant use of modules. You're much better off using Johel's branch that has decent module support (https://github.com/JohelEGP/cppfront, branch cpp_modules). (..)

I can confirm that with commit dacf98c of https://github.com/JohelEGP/cppfront (branch cpp_modules) this bug here doesn't exist.

The cpp1 output file has a correct global module fragment. Declarations and includes are at the right places for example with this .cpp2 input file:

module foo;

import bar;

bla: namespace = {

}

the output file is (correct):

module;

#include "cpp2util.h"

module foo;

import bar;

//=== Cpp2 type declarations ====================================================

#line 1 "x.cpp2"

#line 5 "x.cpp2"
namespace bla {

}


//=== Cpp2 type definitions and function declarations ===========================

#line 1 "x.cpp2"

#line 5 "x.cpp2"
namespace bla {

}


//=== Cpp2 function definitions =================================================

#line 1 "x.cpp2"

#line 5 "x.cpp2"
namespace bla {

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants