Skip to content

<type_traits> add declval failure assertion for instantiation (#2087)#2101

Merged
StephanTLavavej merged 1 commit into
microsoft:mainfrom
michael-herwig:bug-2087-declval-evaluated-context
Aug 17, 2021
Merged

<type_traits> add declval failure assertion for instantiation (#2087)#2101
StephanTLavavej merged 1 commit into
microsoft:mainfrom
michael-herwig:bug-2087-declval-evaluated-context

Conversation

@michael-herwig
Copy link
Copy Markdown

The static assertion will prevent the instantiation of ::std::declval at compile-time, preventing its' usage in an evaluated context.

Fixes #2087 .

@michael-herwig michael-herwig requested a review from a team as a code owner August 7, 2021 08:24
…oft#2087)

The static assertion will prevent the instantiation of ::std::declval
at compile-time, preventing its' usage in an evaluated context.
@michael-herwig michael-herwig force-pushed the bug-2087-declval-evaluated-context branch from b8a25ef to aa26192 Compare August 7, 2021 08:40
Copy link
Copy Markdown
Contributor

@fsb4000 fsb4000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Aug 8, 2021
@AlexGuteniev
Copy link
Copy Markdown
Contributor

AlexGuteniev commented Aug 8, 2021

Not sure if it would produce a warning about missing return statement even thought unevaluated. If no such warning, that's fine. If there is... maybe call to abort?

Edit: actually I think if is unlikely to have a warning/error here, and if there is, it would be compiler bug.

@michael-herwig
Copy link
Copy Markdown
Author

Yes, I thought about that as well. I looked it up at gcc, and they need a return statement. However, in this codebase, other usages of _Always_false omit a return statement as well. I tested the behavior for cl and clang-cl, and both don't yield any confusing return statement warning. I don't know if it's a bug to yield any warning, but a return statement would be a more robust solution for potentially upcoming compiler changes. I finally decided on this approach because it's more consistent with the existing codebase and has less code to maintain.

@CaseyCarter CaseyCarter removed their assignment Aug 12, 2021
@CaseyCarter
Copy link
Copy Markdown
Contributor

It's a shame we don't need a return statement; I was going to suggest return _STD declval<_Ty>(); 😄

@StephanTLavavej StephanTLavavej self-assigned this Aug 14, 2021
@StephanTLavavej
Copy link
Copy Markdown
Member

I'm mirroring this to an MSVC-internal PR. Please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 50d3510 into microsoft:main Aug 17, 2021
@StephanTLavavej
Copy link
Copy Markdown
Member

Thanks for enforcing this Standard-mandated requirement, and congratulations on your first microsoft/STL commit! 🎉 😸 🚀

This will ship in VS 2022 17.1 Preview 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<type_traits>: declval<T>() does not reject use in an evaluated context

7 participants