-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<tuple>: correct get
couldn't be found for struct inheriting from tuple
#121
Comments
get
couldn't be found for struct inherited from std::tuple get
couldn't be found for struct inherited tuple
Aside: Your program formally has undefined behavior due to use of the reserved identifier
Our When you pass an instance of a specialization of static_assert(std::get<0>(tuple<int, double, void*>{42, 3.14, nullptr})); the compiler must deduce If we instead derive a type from a specialization of struct S : std::tuple<int, double, void*> {}; and attempt to pass an object of that type to static_assert(std::get<0>(S{{42, 3.14, nullptr}}) == 42); the compiler must deduce
Now things get messy. The C++ Standard provides no rule to disambiguate which of these four different bases should be chosen, so a conforming compiler must throw its hands in the air, say the deduction fails due to ambiguity, and that it can't call |
@CaseyCarter, thanks for the explanation. What is the advise in this case? |
get
couldn't be found for struct inherited tuple get
couldn't be found for struct inheriting from tuple
I have a prototype indicating that we can flatten the inheritance while preserving layout, so it may be possible. |
I don't know of a way to make the wrapper work with using std::get;
get<X>(e); at callsites that need to handle both template<std::size_t I, class T>
constexpr decltype(auto) adl_get(T&& t) noexcept {
using std::get;
return get<I>(std::forward<T>(t));
} and use that at your callsites. (Caveat: |
This is outdated; CWG fixed it in Kona via CWG2303. |
Summary: Previously, a derived class, WithTuple, was used. This ran into bugs in MSVC (see microsoft/STL#121). Instead, use specialization to get the same result using std::tuple directly. This avoids the bug, and is a cleaner API. Changelog: [Internal] Reviewed By: dulinriley Differential Revision: D21233677 fbshipit-source-id: 1d75991847164e525b4ba70f65a90627e5f8cd56
Summary: Previously, a derived class, WithTuple, was used. This ran into bugs in MSVC (see microsoft/STL#121). Instead, use specialization to get the same result using std::tuple directly. This avoids the bug, and is a cleaner API. Changelog: [Internal] Reviewed By: dulinriley Differential Revision: D21233677 fbshipit-source-id: 1d75991847164e525b4ba70f65a90627e5f8cd56
If transition::Row inherits from std::tuple and (in a later commit) transition::Table inherits from std::tuple, std::get may fail to type deduction due to ambiguity[1]. This commit updates transition Row to contain a std::tuple as a private data member instead of inheriting from std::tuple. As accessor is provided for lookup. An rvalue reference qualified member function is provided for extracting the tuple in order to update a Row with a new Transition. [1]: microsoft/STL#121
@StephanTLavavej, is it implemented in STL now? |
To clarify for myself: Are you saying that the error appears, even, if
is defined or only without it? In your example, that definition is disabled through the |
The error appears if that function is not defined |
@capatober No, I didn't implement that |
I think this has been fixed by implementing CWG-2303 in Clang 12. |
Hi,
It was found that the code below doesn't compile on Windows with clang++. Here we create a class inherits
tuple
and try to callget
for it.I use Visual Studio 2019. Version 16.2.3. Compiler
clang++
Could you please help to identify what is the root case of the problem?
The text was updated successfully, but these errors were encountered: