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++20] [Modules] We don't merge deduction guide correctly #56916

Closed
ChuanqiXu9 opened this issue Aug 4, 2022 · 3 comments
Closed

[C++20] [Modules] We don't merge deduction guide correctly #56916

ChuanqiXu9 opened this issue Aug 4, 2022 · 3 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules

Comments

@ChuanqiXu9
Copy link
Member

ChuanqiXu9 commented Aug 4, 2022

Reproducer:

// foo.h
template <typename T>
class Templ {
public:
    Templ(T a) {}
};

// A.cppm
module;
#include "foo.h"
export module M:A;
export using ::Templ;

// B.cppm
module;
#include "foo.h"
export module M:B;

// M.cppm
export module M;
export import :A;
export import :B;

// Use.cpp
import M;

void func() {
    Templ t(5);
}

Compile it by:

clang++ -std=c++20 --precompile A.cppm -o M-A.pcm
clang++ -std=c++20 --precompile B.cppm -o M-B.pcm
clang++ -std=c++20 --precompile M.cppm -fprebuilt-module-path=.  -o M.pcm
clang++ -std=c++20 Use.cpp -fprebuilt-module-path=. -fsyntax-only

then we'll meet:

Use.cpp:4:11: error: ambiguous deduction for template arguments of 'Templ'
    Templ t(5);
          ^
/home/chuanqi.xcq/workspace.xuchuanqi/llvm-project-for-work/build/modules_deduction_guide/foo.h:4:5: note: candidate function [with T = int]
    Templ(T a) {}
    ^
/home/chuanqi.xcq/workspace.xuchuanqi/llvm-project-for-work/build/modules_deduction_guide/foo.h:4:5: note: candidate function [with T = int]

The error message is clearly wrong.

A workaround could be to add a user-defined deduction guide:

// foo.h
template <typename T>
class Templ {
public:
    Templ(T a) {}
};

template<typename T>
Templ(T t) -> Templ<T>;
@ChuanqiXu9 ChuanqiXu9 added the clang:modules C++20 modules and Clang Header Modules label Aug 4, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 4, 2022

@llvm/issue-subscribers-clang-modules

@aaronmondal
Copy link
Member

This manifests in libcxx/include/__iterator/back_insert_iterator.h. Applying the proposed workaround appears to temporarily fix the issue.

diff --git a/libcxx/include/__iterator/back_insert_iterator.h b/libcxx/include/__iterator/back_insert_iterator.h
index da58b860e3..9aec7aa7cf 100644
--- a/libcxx/include/__iterator/back_insert_iterator.h
+++ b/libcxx/include/__iterator/back_insert_iterator.h
@@ -67,6 +67,9 @@ back_inserter(_Container& __x)
     return back_insert_iterator<_Container>(__x);
 }

+template <class _Container> _LIBCPP_HIDE_FROM_ABI
+back_insert_iterator(_Container& __x) -> back_insert_iterator<_Container>;
+
 _LIBCPP_END_NAMESPACE_STD

 #endif // _LIBCPP___ITERATOR_BACK_INSERT_ITERATOR_H

@ChuanqiXu9
Copy link
Member Author

Yeah, it looks like the compiler can't do a good job for implicit deduction guide now. But due to the deduction guide is mainly grammar sugar for me. So the priority may be relatively low now..

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

3 participants