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

Seemingly incorrect treatment of constexpr member functions in modules #107673

Closed
kamrann opened this issue Sep 7, 2024 · 5 comments
Closed

Seemingly incorrect treatment of constexpr member functions in modules #107673

kamrann opened this issue Sep 7, 2024 · 5 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules constexpr Anything related to constant evaluation release:backport

Comments

@kamrann
Copy link

kamrann commented Sep 7, 2024

According to the standard, member functions defined within a class definition are implicitly inline in the global module, but not so within a module purview. However, the standard also states that constexpr member functions are implicitly inline, and in this case makes no exception for modules.

11.4.2/1 [class.mfct] - see also Note 1
9.2.6/1 [dcl.constexpr]

As such all constexpr member functions should be inline, regardless of modules. From what I can see, clang is not respecting this. I'm seeing linker errors for such member functions when using modules with shared libraries.

I believe the difference between clang and gcc seen here is fundamentally the cause. Clang is generating code for a function marked constexpr but not for one marked inline constexpr, yet if I'm interpreting the standard correctly these cases should be equivalent.

@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules constexpr Anything related to constant evaluation and removed new issue labels Sep 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 7, 2024

@llvm/issue-subscribers-clang-modules

Author: Cameron Angus (kamrann)

According to the standard, member functions defined within a class definition are implicitly `inline` in the global module, but not so within a module purview. However, the standard also states that `constexpr` member functions are implicitly inline, and in this case makes no exception for modules.

[11.4.2/1 [class.mfct] - see also Note 1](https://eel.is/c++draft/class.mfct#1)
[9.2.6/1 [dcl.constexpr]](https://eel.is/c++draft/dcl.constexpr#1)

As such all constexpr member functions should be inline, regardless of modules. From what I can see, clang is not respecting this. I'm seeing linker errors for such member functions when using modules with shared libraries.

I believe the difference between clang and gcc seen here is fundamentally the cause. Clang is generating code for a function marked constexpr but not for one marked inline constexpr, yet if I'm interpreting the standard correctly these cases should be equivalent.

@ChuanqiXu9 ChuanqiXu9 self-assigned this Sep 9, 2024
@kamrann
Copy link
Author

kamrann commented Sep 9, 2024

Latest now behaving as I expected. Thank you!

VitaNuo pushed a commit to VitaNuo/llvm-project that referenced this issue Sep 12, 2024
@ChuanqiXu9
Copy link
Member

Given 19.x is released and both the fixes are simple. I'd like to try to back them.

@ChuanqiXu9
Copy link
Member

/cherry-pick 74ac96a

llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Sep 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

/pull-request #109076

@tru tru moved this from Needs Triage to Done in LLVM Release Status Sep 24, 2024
tru pushed a commit to llvmbot/llvm-project that referenced this issue Sep 24, 2024
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 constexpr Anything related to constant evaluation release:backport
Projects
Development

No branches or pull requests

4 participants