Skip to content

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

Merged
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
frederick-vs-ja:get-by-type-err-msg
Apr 12, 2024
Merged

<tuple>, <variant>: Make error messages from get-by-type functions clearer#4578
Stephan T. Lavavej (StephanTLavavej) merged 3 commits into
microsoft:mainfrom
frederick-vs-ja:get-by-type-err-msg

Conversation

@frederick-vs-ja

Copy link
Copy Markdown
Contributor

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

Comment thread stl/inc/tuple Outdated
Comment thread stl/inc/tuple Outdated
@StephanTLavavej

Copy link
Copy Markdown
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
Copy Markdown
Member

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

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 9aca224 into microsoft:main Apr 12, 2024
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks again for this massive diagnostic improvement! 🪄 🚀 😻

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

None yet

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