llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.81k stars 11.45k forks source link

clang recursive module tuple failure #97377

Open mmoult opened 2 months ago

mmoult commented 2 months ago

files.tar.gz

I am unable to compile the attached files using CMake and Ninja. Here is the error(s) I get:

again/main.cpp:7:11: error: no matching function for call to 'get'
    7 |     auto [a, s] = again.next("something");
      |           ^
again/main.cpp:7:11: note: in implicit initialization of binding declaration 'a'
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:855:5: note: candidate template ignored: could not match 'pair' against 'tuple'
  855 |     get(pair<_Tp1, _Tp2>& __in) noexcept
      |     ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:860:5: note: candidate template ignored: could not match 'pair' against 'tuple'
  860 |     get(pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:865:5: note: candidate template ignored: could not match 'pair' against 'tuple'
  865 |     get(const pair<_Tp1, _Tp2>& __in) noexcept
      |     ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:870:5: note: candidate template ignored: could not match 'pair' against 'tuple'
  870 |     get(const pair<_Tp1, _Tp2>&& __in) noexcept
      |     ^
...

The code has no issues compiling if I change tuple -> pair, but that shouldn't be an issue. The same code compiles without any errors if I change again.cxx from module syntax to a header file (and change the CMakeFile and main import to correspond). This indicates to me there is a bug with the module compilation.

llvmbot commented 2 months ago

@llvm/issue-subscribers-clang-frontend

Author: Matthew Moulton (mmoult)

[files.tar.gz](https://github.com/user-attachments/files/16060923/files.tar.gz) I am unable to compile the attached files using CMake and Ninja. Here is the error(s) I get: ``` again/main.cpp:7:11: error: no matching function for call to 'get' 7 | auto [a, s] = again.next("something"); | ^ again/main.cpp:7:11: note: in implicit initialization of binding declaration 'a' /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:855:5: note: candidate template ignored: could not match 'pair' against 'tuple' 855 | get(pair<_Tp1, _Tp2>& __in) noexcept | ^ /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:860:5: note: candidate template ignored: could not match 'pair' against 'tuple' 860 | get(pair<_Tp1, _Tp2>&& __in) noexcept | ^ /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:865:5: note: candidate template ignored: could not match 'pair' against 'tuple' 865 | get(const pair<_Tp1, _Tp2>& __in) noexcept | ^ /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:870:5: note: candidate template ignored: could not match 'pair' against 'tuple' 870 | get(const pair<_Tp1, _Tp2>&& __in) noexcept | ^ ... ``` The code has no issues compiling if I change tuple -> pair, but that shouldn't be an issue. The same code compiles without any errors if I change again.cxx from module syntax to a header file (and change the CMakeFile and main import to correspond). This indicates to me there is a bug with the module compilation.
shafik commented 2 months ago

CC @ChuanqiXu9

llvmbot commented 2 months ago

@llvm/issue-subscribers-clang-modules

Author: Matthew Moulton (mmoult)

[files.tar.gz](https://github.com/user-attachments/files/16060923/files.tar.gz) I am unable to compile the attached files using CMake and Ninja. Here is the error(s) I get: ``` again/main.cpp:7:11: error: no matching function for call to 'get' 7 | auto [a, s] = again.next("something"); | ^ again/main.cpp:7:11: note: in implicit initialization of binding declaration 'a' /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:855:5: note: candidate template ignored: could not match 'pair' against 'tuple' 855 | get(pair<_Tp1, _Tp2>& __in) noexcept | ^ /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:860:5: note: candidate template ignored: could not match 'pair' against 'tuple' 860 | get(pair<_Tp1, _Tp2>&& __in) noexcept | ^ /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:865:5: note: candidate template ignored: could not match 'pair' against 'tuple' 865 | get(const pair<_Tp1, _Tp2>& __in) noexcept | ^ /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:870:5: note: candidate template ignored: could not match 'pair' against 'tuple' 870 | get(const pair<_Tp1, _Tp2>&& __in) noexcept | ^ ... ``` The code has no issues compiling if I change tuple -> pair, but that shouldn't be an issue. The same code compiles without any errors if I change again.cxx from module syntax to a header file (and change the CMakeFile and main import to correspond). This indicates to me there is a bug with the module compilation.
ChuanqiXu9 commented 2 months ago

Interestingly, I can't reproduce the same failure but got:

main.cpp:7:10: error: cannot decompose class type 'tuple<const Again , std::basic_string>': its base classes '_Head_base<1UL, basic_string<char, char_traits, allocator>>' and '_Head_base<0UL, const Again >' have non-static data members 7 | auto [a, s] = again.next("something"); | ^

mmoult commented 2 months ago

The build of clang I was running when I encountered the error is a couple weeks old. I didn't think that would make a difference, but I will try with top of tree to compare against your error.

Unless I am mistaken, the code should compile (and therefore, any error is a bug).

mmoult commented 2 months ago

Here are the versions of the tools I used to reproduce the error I described originally:

ChuanqiXu9 commented 2 months ago

Maybe it is related to the version of libstdc++. I see you're using 12 and I am using 10.

While this should be a bug and need to be fixed, I suggest you to use libc++ as workaround especially you can try std module that way.