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

<tuple>, <variant>: Make error messages from get-by-type functions clearer #4578

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

frederick-vs-ja
Copy link
Contributor

Fixes #4575 by aborting recursive instantiation using if constexpr.
Also reuses _Meta_find_unique_index for overloads for tuple.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner April 11, 2024 18:26
@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Apr 11, 2024
@StephanTLavavej StephanTLavavej self-assigned this Apr 11, 2024
stl/inc/tuple Outdated Show resolved Hide resolved
stl/inc/tuple Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

Thanks! 😻 Your new static_asserts are beautiful:

D:\GitHub\STL\out\x64>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /c meow.cpp
meow.cpp
D:\GitHub\STL\out\x64\out\inc\tuple(957): error C2338: static_assert failed: 'get<T>(tuple<Types...>&) requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)'
D:\GitHub\STL\out\x64\out\inc\tuple(957): note: the template instantiation context (the oldest one first) is
meow.cpp(5): note: see reference to function template instantiation '_Ty &std::get<float,int,long,double>(std::tuple<int,long,double> &) noexcept' being compiled
        with
        [
            _Ty=float
        ]

D:\GitHub\STL\out\x64>clang-cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /c meow.cpp
In file included from meow.cpp:1:
D:\GitHub\STL\out\x64\out\inc\tuple(957,23): error: static assertion failed due to requirement '_Always_false<float>':
      get<T>(tuple<Types...>&) requires T to occur exactly once in Types. (N4971 [tuple.elem]/5)
  957 |         static_assert(_Always_false<_Ty>,
      |                       ^~~~~~~~~~~~~~~~~~
meow.cpp(5,12): note: in instantiation of function template specialization 'std::get<float, int, long, double>'
      requested here
    5 |     (void) get<float>(t);
      |            ^
1 error generated.

I pushed a simplification/throughput improvement and a Standard citation fix.

@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 9aca224 into microsoft:main Apr 12, 2024
35 checks passed
@StephanTLavavej
Copy link
Member

Thanks again for this massive diagnostic improvement! 🪄 🚀 😻

@frederick-vs-ja frederick-vs-ja deleted the get-by-type-err-msg branch April 12, 2024 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

<tuple>: Confusing diagnostic for get<T>() when the type doesn't occur exactly once
2 participants