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

defining struct/class code and finishing impl later in an export { } block #61890

Closed
ar-visions opened this issue Apr 1, 2023 · 6 comments
Closed
Labels
clang:modules C++20 modules and Clang Header Modules wontfix Issue is real, but we can't or won't fix it. Not invalid

Comments

@ar-visions
Copy link

ar-visions commented Apr 1, 2023

module;

export module test_mod;

export {
struct test_me {
    void test_method();
};

void test_me::test_method() { /// fatal error: cannot export 'test_method' as it is not at namespace scope [?]
    printf("test");
}
}

// this works:
module;

export module test_mod;

export struct test_me {
    void test_method();
};

void test_me::test_method() { /// works.
    printf("test");
}


// this also works:
module;

export module test_mod;

export {
struct test_me {
    void test_method();
};
}

void test_me::test_method() { /// works.
    printf("test");
}

version / target:

clang version 17.0.0 (https://github.com/llvm/llvm-project f66b9fe5876d670b38351c9a7efd90e793f35a30)
Target: arm64-apple-darwin22.3.0

my issue:
...putting it all in export { } works on MSVC. its declared exported above and finished inside. What namespace would it be referring to? if the export { } creates the namespace its certainly inside it in the error case?

@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules and removed new issue labels Apr 1, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 1, 2023

@llvm/issue-subscribers-clang-modules

@ChuanqiXu9
Copy link
Member

what namespace would it be referring to?

In this case it refers to the global namespace. The standard says we shouldn't export things which are not in namespace scope. I think the current behavior may not be wrong simply. Maybe MSVC is smarter in this case.

@ar-visions
Copy link
Author

ar-visions commented Apr 4, 2023

so that namespace association should fall through based on it being exported at expression of struct/class (because it cannot be expressed at the membership level)? just trying to wrap head around.

with most of these things it seems obvious to post an issue at the time and then I find the redundancies in a way. still, it seems lossless to have a little fix in place for that.

@ChuanqiXu9
Copy link
Member

so that namespace association should fall through based on it being exported at expression of struct/class (because it cannot be expressed at the membership level)? just trying to wrap head around.

I am not sure if I understand your question well. But the export block is a transparent context. In other words, it doesn't have semantical meaning to the process of lookups. Or you can think it is orthogonal with namespaces.

@ar-visions
Copy link
Author

ar-visions commented Apr 4, 2023

Thank you. If I find where this is applied, would a PR be acceptable to fix?

@ChuanqiXu9
Copy link
Member

Thank you. If I find where this is applied, would a PR be acceptable to fix?

No... I know where this is applied. I mean this may not be good to be fixed... Since we don't want the users to think they can export the entities which are not at namespace scope. This is by design.

@EugeneZelenko EugeneZelenko added the wontfix Issue is real, but we can't or won't fix it. Not invalid label Apr 4, 2023
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules wontfix Issue is real, but we can't or won't fix it. Not invalid
Projects
None yet
Development

No branches or pull requests

4 participants