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

[C++23] [Modules] -fskip-odr-check-in-gmf results in "redefinition of concept" error #87609

Closed
jiixyj opened this issue Apr 4, 2024 · 4 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules

Comments

@jiixyj
Copy link
Contributor

jiixyj commented Apr 4, 2024

I'm testing with LLVM/Clang head (607b4bc). I have some code where I #include after doing an import:

import utpp;
#include <fstream>
#include <numeric>
#include <streambuf>
#include <string>

When compiling with -fskip-odr-check-in-gmf (which is the default now, I think), I'm getting a "redefinition of concept" error:

/llvm-project/prefix/bin/clang++   -m64 -stdlib=libc++ -Xclang -fskip-odr-check-in-gmf -Wno-deprecated-declarations -O2 -g -DNDEBUG -std=c++23 -fcolor-diagnostics -MD -MT example/CMakeFiles/utpp_gherkin_feature.dir/gherkin.cpp.o -MF example/CMakeFiles/utpp_gherkin_feature.dir/gherkin.cpp.o.d @example/CMakeFiles/utpp_gherkin_feature.dir/gherkin.cpp.o.modmap -o example/CMakeFiles/utpp_gherkin_feature.dir/gherkin.cpp.o -c /home/jan/git/utpp/example/gherkin.cpp
In file included from /home/jan/git/utpp/example/gherkin.cpp:9:
In file included from /llvm-project/prefix/bin/../include/c++/v1/fstream:199:                           
In file included from /llvm-project/prefix/bin/../include/c++/v1/filesystem:538:                        
In file included from /llvm-project/prefix/bin/../include/c++/v1/__filesystem/directory_entry.h:20:     
In file included from /llvm-project/prefix/bin/../include/c++/v1/__filesystem/filesystem_error.h:15:    
In file included from /llvm-project/prefix/bin/../include/c++/v1/__filesystem/path.h:30:                
In file included from /llvm-project/prefix/bin/../include/c++/v1/iomanip:46:                            
In file included from /llvm-project/prefix/bin/../include/c++/v1/istream:170:                           
In file included from /llvm-project/prefix/bin/../include/c++/v1/ostream:188:
In file included from /llvm-project/prefix/bin/../include/c++/v1/format:194:
In file included from /llvm-project/prefix/bin/../include/c++/v1/__format/container_adaptor.h:20:
In file included from /llvm-project/prefix/bin/../include/c++/v1/__format/range_default_formatter.h:23:
In file included from /llvm-project/prefix/bin/../include/c++/v1/__format/range_formatter.h:23:
In file included from /llvm-project/prefix/bin/../include/c++/v1/__format/format_context.h:30:
/llvm-project/prefix/bin/../include/c++/v1/optional:565:9: error: redefinition of concept '__is_derived_from_optional' with different template parameters or requirem
ents
  565 | concept __is_derived_from_optional = requires(const _Tp& __t) { []<class _Up>(const optional<_Up>&) {}(__t); };
      |         ^
/llvm-project/prefix/bin/../include/c++/v1/__ranges/movable_box.h:21:10: note: '/llvm-project/prefix/bin/../include/c++/v1/optional' inclu
ded multiple times, additional include site in header from module 'std.<global>'
   21 | #include <optional>
      |          ^
/llvm-project/prefix/share/libc++/v1/std.cppm:14:1: note: std.<global> defined here
   14 | module;
      | ^
/llvm-project/prefix/bin/../include/c++/v1/__format/format_context.h:30:12: note: '/llvm-project/prefix/bin/../include/c++/v1/optional' in
cluded multiple times, additional include site here
   30 | #  include <optional>
      |            ^

When compiling with -fno-skip-odr-check-in-gmf, it finishes compiling without error. Which is curious, since I had assumed that enabling -fskip-odr-check-in-gmf would always result in less errors, not more.

Another data point: on LLVM/Clang from 2024-02-22, this compiled without error without any additional compiler arguments.

So now, I have to do one of the following to make the error go away:

  • Specify -fno-skip-odr-check-in-gmf
  • or move the import after the #includes

Has anyone an idea how/why this could happen? I could try to bisect this, but this could take a while...

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

llvmbot commented Apr 4, 2024

@llvm/issue-subscribers-clang-modules

Author: Jan Kokemüller (jiixyj)

I'm testing with LLVM/Clang head (607b4bc). I have some code where I `#include` _after_ doing an `import`:
import utpp;
#include &lt;fstream&gt;
#include &lt;numeric&gt;
#include &lt;streambuf&gt;
#include &lt;string&gt;

When compiling with -fskip-odr-check-in-gmf (which is the default now, I think), I'm getting a "redefinition of concept" error:

/llvm-project/prefix/bin/clang++   -m64 -stdlib=libc++ -Xclang -fskip-odr-check-in-gmf -Wno-deprecated-declarations -O2 -g -DNDEBUG -std=c++23 -fcolor-diagnostics -MD -MT example/CMakeFiles/utpp_gherkin_feature.dir/gherkin.cpp.o -MF example/CMakeFiles/utpp_gherkin_feature.dir/gherkin.cpp.o.d @<!-- -->example/CMakeFiles/utpp_gherkin_feature.dir/gherkin.cpp.o.modmap -o example/CMakeFiles/utpp_gherkin_feature.dir/gherkin.cpp.o -c /home/jan/git/utpp/example/gherkin.cpp
In file included from /home/jan/git/utpp/example/gherkin.cpp:9:
In file included from /llvm-project/prefix/bin/../include/c++/v1/fstream:199:                           
In file included from /llvm-project/prefix/bin/../include/c++/v1/filesystem:538:                        
In file included from /llvm-project/prefix/bin/../include/c++/v1/__filesystem/directory_entry.h:20:     
In file included from /llvm-project/prefix/bin/../include/c++/v1/__filesystem/filesystem_error.h:15:    
In file included from /llvm-project/prefix/bin/../include/c++/v1/__filesystem/path.h:30:                
In file included from /llvm-project/prefix/bin/../include/c++/v1/iomanip:46:                            
In file included from /llvm-project/prefix/bin/../include/c++/v1/istream:170:                           
In file included from /llvm-project/prefix/bin/../include/c++/v1/ostream:188:
In file included from /llvm-project/prefix/bin/../include/c++/v1/format:194:
In file included from /llvm-project/prefix/bin/../include/c++/v1/__format/container_adaptor.h:20:
In file included from /llvm-project/prefix/bin/../include/c++/v1/__format/range_default_formatter.h:23:
In file included from /llvm-project/prefix/bin/../include/c++/v1/__format/range_formatter.h:23:
In file included from /llvm-project/prefix/bin/../include/c++/v1/__format/format_context.h:30:
/llvm-project/prefix/bin/../include/c++/v1/optional:565:9: error: redefinition of concept '__is_derived_from_optional' with different template parameters or requirem
ents
  565 | concept __is_derived_from_optional = requires(const _Tp&amp; __t) { []&lt;class _Up&gt;(const optional&lt;_Up&gt;&amp;) {}(__t); };
      |         ^
/llvm-project/prefix/bin/../include/c++/v1/__ranges/movable_box.h:21:10: note: '/llvm-project/prefix/bin/../include/c++/v1/optional' inclu
ded multiple times, additional include site in header from module 'std.&lt;global&gt;'
   21 | #include &lt;optional&gt;
      |          ^
/llvm-project/prefix/share/libc++/v1/std.cppm:14:1: note: std.&lt;global&gt; defined here
   14 | module;
      | ^
/llvm-project/prefix/bin/../include/c++/v1/__format/format_context.h:30:12: note: '/llvm-project/prefix/bin/../include/c++/v1/optional' in
cluded multiple times, additional include site here
   30 | #  include &lt;optional&gt;
      |            ^

When compiling with -fno-skip-odr-check-in-gmf, it finishes compiling without error. Which is curious, since I had assumed that enabling -fskip-odr-check-in-gmf would always result in less errors, not more.

Another data point: on LLVM/Clang from 2024-02-22, this compiled without error without any additional compiler arguments.

So now, I have to do one of the following to make the error go away:

  • Specify -fno-skip-odr-check-in-gmf
  • or move the import after the #includes

Has anyone an idea how/why this could happen? I could try to bisect this, but this could take a while...

@ChuanqiXu9 ChuanqiXu9 self-assigned this Apr 7, 2024
@ChuanqiXu9
Copy link
Member

I guess the reason may be that we used ODRHash to merge concepts in (import-before-include) path. A reduced (without any stl) may be helpful.

@ChuanqiXu9
Copy link
Member

Although I marked this as closed in the commit, I didn't try the original reproducer. So feel free to reopen this if there is still problems.

@jiixyj
Copy link
Contributor Author

jiixyj commented Apr 16, 2024

Thank you! I can confirm that the fix works. I tested with 8cee94e .

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

No branches or pull requests

4 participants