Skip to content

<xstring>: basic_string::_Is_elem_cptr should be a variable template#2980

Merged
StephanTLavavej merged 6 commits into
microsoft:mainfrom
YairBorn:Hotfix
Aug 9, 2022
Merged

<xstring>: basic_string::_Is_elem_cptr should be a variable template#2980
StephanTLavavej merged 6 commits into
microsoft:mainfrom
YairBorn:Hotfix

Conversation

@YairBorn
Copy link
Copy Markdown
Contributor

@YairBorn YairBorn commented Aug 1, 2022

fixes #2898

@YairBorn YairBorn requested a review from a team as a code owner August 1, 2022 10:35
@cpplearner
Copy link
Copy Markdown
Contributor

You can see how existing variable templates are defined, e.g. :

STL/stl/inc/xtr1common

Lines 189 to 190 in b7e0365

template <class _Ty>
_INLINE_VAR constexpr bool is_floating_point_v = _Is_any_of_v<remove_cv_t<_Ty>, float, double, long double>;

But since _Is_elem_cptr is a member, you should use static in place of _INLINE_VAR.

After making _Is_elem_cptr a variable template, you should also change all occurences of _Is_elem_cptr<something>::value to _Is_elem_cptr<something>.

@YairBorn
Copy link
Copy Markdown
Contributor Author

YairBorn commented Aug 1, 2022

You can see how existing variable templates are defined, e.g. :

STL/stl/inc/xtr1common

Lines 189 to 190 in b7e0365

template <class _Ty>
_INLINE_VAR constexpr bool is_floating_point_v = _Is_any_of_v<remove_cv_t<_Ty>, float, double, long double>;

But since _Is_elem_cptr is a member, you should use static in place of _INLINE_VAR.

After making _Is_elem_cptr a variable template, you should also change all occurences of _Is_elem_cptr<something>::value to _Is_elem_cptr<something>.

i think i fixed it in daddfb2
can you please take a look on what i did?

Comment thread stl/inc/xstring Outdated
@frederick-vs-ja
Copy link
Copy Markdown
Contributor

Great, and further improvement can be done.
Note that

You can (and should) link your pull request to this issue using GitHub's close/fix/resolve syntax.
(in the PR description not the commit message)

@CaseyCarter CaseyCarter changed the title fixed <xstring>: basic_string::_Is_elem_cptr should be a variable template <xstring>: basic_string::_Is_elem_cptr should be a variable template Aug 1, 2022
@CaseyCarter CaseyCarter added the enhancement Something can be improved label Aug 1, 2022
Comment thread stl/inc/xstring Outdated
@StephanTLavavej StephanTLavavej self-assigned this Aug 3, 2022
@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
Copy link
Copy Markdown
Member

Unfortunately, while this change is correct, it triggers a /clr:pure compiler bug which is unlikely to ever be fixed:

test.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '???__E??$_Is_elem_cptr@PAD@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$$Q0_NB@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@YMXXZ@?A0xbffd14b2@@$$FYMXXZ'

(Noticed only when mirroring to the MSVC-internal repo, as we haven't gotten around to porting the /clr:pure build to GitHub yet.)

@YairBorn
Copy link
Copy Markdown
Contributor Author

YairBorn commented Aug 3, 2022

Unfortunately, while this change is correct, it triggers a /clr:pure compiler bug which is unlikely to ever be fixed:

test.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '???__E??$_Is_elem_cptr@PAD@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$$Q0_NB@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@YMXXZ@?A0xbffd14b2@@$$FYMXXZ'

(Noticed only when mirroring to the MSVC-internal repo, as we haven't gotten around to porting the /clr:pure build to GitHub yet.)

There's no solution to this compiler error?

@jovibor
Copy link
Copy Markdown
Contributor

jovibor commented Aug 3, 2022

while this change is correct, it triggers a /clr:pure compiler bug

According to the docs:

/clr:pure is deprecated. The option is removed in Visual Studio 2017 and later.

It was deprecated long time ago, so why even bother? 🥱

@YairBorn YairBorn requested review from cpplearner, frederick-vs-ja and miscco and removed request for cpplearner and frederick-vs-ja August 3, 2022 10:52
@miscco
Copy link
Copy Markdown
Contributor

miscco commented Aug 3, 2022

Unfortunately, while this change is correct, it triggers a /clr:pure compiler bug which is unlikely to ever be fixed:

test.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '???__E??$_Is_elem_cptr@PAD@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$$Q0_NB@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@YMXXZ@?A0xbffd14b2@@$$FYMXXZ'

(Noticed only when mirroring to the MSVC-internal repo, as we haven't gotten around to porting the /clr:pure build to GitHub yet.)

Urgh, Now it remember that I had that change in the ASAN string branch and pulled it out because of this failure :(

@StephanTLavavej
Copy link
Copy Markdown
Member

@YairBorn

There's no solution to this compiler error?

Unfortunately, there isn't - we aren't aware of any workarounds, and the compiler team hasn't found a way to fix this longstanding issue (which involves name mangling, and hence binary compatibility). 😿

While we can't merge this change, this code could instead be commented as to why we aren't using a static constexpr data member. Would you like to change your PR to do that? We mark issues that can be addressed in the (possibly far) future as "TRANSITION" (indicating a temporary state of affairs), followed by a short explanation. Here, // TRANSITION, /clr:pure is incompatible with templated static constexpr data members would be a reasonable explanation. (Note that we have a 120 column limit for code format validation.)

@StephanTLavavej StephanTLavavej removed their assignment Aug 3, 2022
@YairBorn
Copy link
Copy Markdown
Contributor Author

YairBorn commented Aug 4, 2022

While we can't merge this change, this code could instead be commented as to why we aren't using a static constexpr data member. Would you like to change your PR to do that? We mark issues that can be addressed in the (possibly far) future as "TRANSITION" (indicating a temporary state of affairs), followed by a short explanation. Here, // TRANSITION, /clr:pure is incompatible with templated static constexpr data members would be a reasonable explanation. (Note that we have a 120 column limit for code format validation.)

If I get you right, you want me to undo all of my changes, and add the comment you mentioned?

@StephanTLavavej
Copy link
Copy Markdown
Member

If I get you right, you want me to undo all of my changes, and add the comment you mentioned?

Yep, that's correct.

@YairBorn
Copy link
Copy Markdown
Contributor Author

YairBorn commented Aug 6, 2022

If I get you right, you want me to undo all of my changes, and add the comment you mentioned?

Yep, that's correct.

Done in YairBorn@60ae0ff

@YairBorn
Copy link
Copy Markdown
Contributor Author

YairBorn commented Aug 7, 2022

If I get you right, you want me to undo all of my changes, and add the comment you mentioned?

Yep, that's correct.

Done in YairBorn@60ae0ff, but o don't know why the tests failed...

Comment thread stl/inc/xstring Outdated
Co-authored-by: Igor Zhukov <[email protected]>
@YairBorn
Copy link
Copy Markdown
Contributor Author

YairBorn commented Aug 7, 2022

If I get you right, you want me to undo all of my changes, and add the comment you mentioned?

Yep, that's correct.

Done. all tests passed! 😸

@CaseyCarter
Copy link
Copy Markdown
Contributor

Urgh, Now it remember that I had that change in the ASAN string branch and pulled it out because of this failure :(

I didn't remember, but I do recall thinking "Why haven't we done this before?" when filing the issue. Hopefully the comment will prevent us from wasting more people's time doing this again in the future.

@CaseyCarter CaseyCarter requested review from StephanTLavavej and strega-nil-ms and removed request for miscco August 8, 2022 17:04
@StephanTLavavej StephanTLavavej self-assigned this Aug 9, 2022
@StephanTLavavej
Copy link
Copy Markdown
Member

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

@StephanTLavavej StephanTLavavej merged commit 9aaab62 into microsoft:main Aug 9, 2022
@StephanTLavavej
Copy link
Copy Markdown
Member

Thanks for working on this change - twice - and documenting why the STL behaves like this. Also, congratulations on your first microsoft/STL commit! 🎉 😻 🚀

This change will ship in VS 2022 17.4 Preview 3.

fsb4000 added a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
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.

<xstring>: basic_string::_Is_elem_cptr should be a variable template

9 participants