Skip to content

Using import after #include may cause redeclaration errors #61329

@rnikander

Description

@rnikander

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):

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:

module;
#include <iostream>
export module foo;
export void foo_func() {
    std::cout << "in foo_func\n";
}

main.cc:

import foo;
#include <iostream>
int main(int argc, char *argv[])
{
    std::cout << "Test\n";
    return 0;
}

Leads to these errors:

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>...>
                             ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:modulesC++20 modules and Clang Header ModulesduplicateResolved as duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions