<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61329>61329</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Using import and #include causes redeclaration errors
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rnikander
</td>
</tr>
</table>
<pre>
I'm new to C++20 modules, so I don't know if this is supposed to work or not. It seems like a C++ file that uses modules and traditional #includes can get errors.
Here is a minimal example, using a recent HEAD (Clang 17).
build.sh (obviously needs to be adjusted a bit for your environment)
```text
CLANG_DIR=/Users/rob/Dev/llvm-project/build
CXX=${CLANG_DIR}/bin/clang++
# Need on my macOS system
ISYS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk"
$CXX $ISYS -std=c++2b foo.ccm --precompile -o foo.pcm
$CXX $ISYS -std=c++2b main.cc -fprebuilt-module-path=. foo.pcm -o final.out
```
foo.ccm:
```c++
module;
#include <iostream>
export module foo;
export void foo_func() {
std::cout << "in foo_func\n";
}
```
main.cc:
```c++
import foo;
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Test\n";
return 0;
}
```
Leads to these errors:
```text
In file included from main.cc:3:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/iostream:43:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/ios:221:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__locale:18:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/mutex:191:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__memory/shared_ptr.h:30:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__memory/uninitialized_algorithms.h:13:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__algorithm/copy.h:12:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__algorithm/copy_move_common.h:14:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__algorithm/unwrap_range.h:19:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__utility/pair.h:13:
/Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__compare/synth_three_way.h:28:45: error: redeclaration of '__synth_three_way' with a different type: 'const std::__1::(lambda at /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__compare/synth_three_way.h:29:3)' vs 'const std::__1::(lambda at /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__compare/synth_three_way.h:29:3)'
_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
^
/Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__compare/synth_three_way.h:28:45: note: previous definition is here
_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
^
In file included from main.cc:3:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/iostream:43:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/ios:221:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__locale:18:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/mutex:191:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__memory/shared_ptr.h:30:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__memory/uninitialized_algorithms.h:13:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__algorithm/copy.h:12:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__algorithm/copy_move_common.h:14:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__algorithm/unwrap_range.h:19:
/Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__utility/pair.h:440:9: error: use of undeclared identifier '__synth_three_way_result'
__synth_three_way_result<_T1>,
^
/Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__utility/pair.h:441:39: error: expected unqualified-id
__synth_three_way_result<_T2> >
^
In file included from main.cc:3:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/iostream:43:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/ios:221:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__locale:18:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/mutex:192:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__mutex_base:20:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/system_error:154:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/string:560:
In file included from /Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/__memory_resource/polymorphic_allocator.h:20:
/Users/rob/Dev/llvm-project/build/bin/../include/c++/v1/tuple:1571:30: error: use of undeclared identifier '__synth_three_way_result'
common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...>
^
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWd1u2zgTfRr6ZmBBpmzLuvCFY8dfja9_aFogeyVQ5NhiQ5FaknLiffoFJcVO0jbtAm3SxcYIAkEkh-dwhmeGFHNO7jTinEzOyGQ1YI0vjZ1bLa-YFmgHhRGH-YbQtAKN1-ANLAk9I_SMxlAZ0Sh0hC7BGdiAMJrQ1MOVNtcgt-BL6UA6cE1dG4cijL429gqMBW18BBsPDrFyoOQVArs1DVupEHzJPDQO3e08wLQAb5mQXhrNFBCaSM1VI9ABZxp26AGtNdZFJF6ReNH9f4UWAwwGldSyYgrwhlW1wgC8cVLvgIFFjtrDq_PFCgidLRXTOxilhGYR3DVWNFKJyJWhkyn20jROHUAjChfoFQhMfG6cRwEMCulhaywcTGMB9V5aoyvUntCstzmNuz-PN757tXy9ePu_fLX5QJIVoetPDq0jdG1NQeh6hXtC10rtq2FtzWfkntB1C6kffHnZDhuT9OxkKA2GCqkJXfPAq1vlu6wITeAtog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