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

[clangd][modules] Clangd reports ODR violation when including iostream from (global module fragment of) two different modules #100924

Open
alfaix opened this issue Jul 28, 2024 · 5 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules clangd

Comments

@alfaix
Copy link

alfaix commented Jul 28, 2024

Hey, I'm trying to get modules to work with clangd following this PR.

However, when I run clangd with the following files:

// b.cppm
module;
#include <iostream>
export module b;

export template <class T>
concept C = requires() {
  { T::foo } -> std::convertible_to<int>;
};

// c.cppm
module;

#include <iostream>

export module c;
import b;
class B {
public:
  static constexpr int foo = 1;
};

export template <class T>
  requires C<T>
class D {};

int main() { D<B> s; }

Put -std=c++23 -stdlib=libc++ and all the -fmodule things in compile_commands.json, clangd reports an ODR violation, saying the 2 definitions of std::error_category from the 2 includes are different: E[12:04:26.095] [module_odr_violation_missing_decl] Line 3: in included file: 'std::error_category::message' from module '' is not present in definition of 'std::error_category' in module 'b.<global>'

The setup is sensitive to small changes - e.g., removing std::convertible from the concept leads to the error disappearing. I put the repro in a small repo for convenience.

Tested with Ubuntu clang version 20.0.0 (++20240727042143+9a3e66e314e6-1~exp1~20240727042317.1828) straight out of apt.llvm.org snapshot repo.

@alfaix alfaix changed the title [clangd+modules] Clangd reports ODR violation when including iostream from (global module fragment of) two different modules [clangd][modules] Clangd reports ODR violation when including iostream from (global module fragment of) two different modules Jul 28, 2024
@alfaix
Copy link
Author

alfaix commented Jul 28, 2024

Could be related to #58540, although there the discussion is about importing header units.

@alfaix
Copy link
Author

alfaix commented Jul 28, 2024

Ah upon closer examination seems to be same as #78850

That said, I thought the -fskip-odr-check-in-gmf should have fixed it for now

@EugeneZelenko EugeneZelenko added clangd clang:modules C++20 modules and Clang Header Modules and removed new issue labels Jul 28, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 28, 2024

@llvm/issue-subscribers-clang-modules

Author: Arsen Kitov (alfaix)

Hey, I'm trying to get modules to work with clangd following [this PR](https://github.com//pull/66462).

However, when I run clangd with the following files:

// b.cppm
module;
#include &lt;iostream&gt;
export module b;

export template &lt;class T&gt;
concept C = requires() {
  { T::foo } -&gt; std::convertible_to&lt;int&gt;;
};

// c.cppm
module;

#include &lt;iostream&gt;

export module c;
import b;
class B {
public:
  static constexpr int foo = 1;
};

export template &lt;class T&gt;
  requires C&lt;T&gt;
class D {};

int main() { D&lt;B&gt; s; }

Put -std=c++23 -stdlib=libc++ and all the -fmodule things in compile_commands.json, clangd reports an ODR violation, saying the 2 definitions of std::error_category from the 2 includes are different: E[12:04:26.095] [module_odr_violation_missing_decl] Line 3: in included file: 'std::error_category::message' from module '' is not present in definition of 'std::error_category' in module 'b.&lt;global&gt;'

The setup is sensitive to small changes - e.g., removing std::convertible from the concept leads to the error disappearing. I put the repro in a small repo for convenience.

Tested with Ubuntu clang version 20.0.0 (++20240727042143+9a3e66e314e6-1~exp1~20240727042317.1828) straight out of apt.llvm.org snapshot repo.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 28, 2024

@llvm/issue-subscribers-clangd

Author: Arsen Kitov (alfaix)

Hey, I'm trying to get modules to work with clangd following [this PR](https://github.com//pull/66462).

However, when I run clangd with the following files:

// b.cppm
module;
#include &lt;iostream&gt;
export module b;

export template &lt;class T&gt;
concept C = requires() {
  { T::foo } -&gt; std::convertible_to&lt;int&gt;;
};

// c.cppm
module;

#include &lt;iostream&gt;

export module c;
import b;
class B {
public:
  static constexpr int foo = 1;
};

export template &lt;class T&gt;
  requires C&lt;T&gt;
class D {};

int main() { D&lt;B&gt; s; }

Put -std=c++23 -stdlib=libc++ and all the -fmodule things in compile_commands.json, clangd reports an ODR violation, saying the 2 definitions of std::error_category from the 2 includes are different: E[12:04:26.095] [module_odr_violation_missing_decl] Line 3: in included file: 'std::error_category::message' from module '' is not present in definition of 'std::error_category' in module 'b.&lt;global&gt;'

The setup is sensitive to small changes - e.g., removing std::convertible from the concept leads to the error disappearing. I put the repro in a small repo for convenience.

Tested with Ubuntu clang version 20.0.0 (++20240727042143+9a3e66e314e6-1~exp1~20240727042317.1828) straight out of apt.llvm.org snapshot repo.

@ChuanqiXu9 ChuanqiXu9 self-assigned this Jul 29, 2024
@ChuanqiXu9
Copy link
Member

Would you like to test again on trunk?

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 clangd
Projects
None yet
Development

No branches or pull requests

4 participants