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

Mark constants as _INLINE_VAR constexpr. #2792

Merged
merged 1 commit into from
Jun 16, 2022

Conversation

StephanTLavavej
Copy link
Member

@cdacamar explained why he's implementing a new compiler warning:

I have been tightening up c1xx's modules implementation by making the compiler more strict and correct when it comes to assigning out linkage to entities emitted into associated .objs.

This warning will complain about non-inline constants in headers. We're almost completely consistent about using inline in C++17-and-later (or _INLINE_VAR in potentially-C++14), but Cameron found our inconsistent occurrences:

C:\msvc\binaries\x86chk\inc\vector(2113): warning C5260: the constant variable 'std::_VBITS' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
C:\msvc\binaries\x86chk\inc\regex(1166): warning C5260: the constant variable 'std::_Buf_incr' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
C:\msvc\binaries\x86chk\inc\functional(725): warning C5260: the constant variable 'std::_Space_size' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
C:\msvc\binaries\x86chk\inc\regex(1158): warning C5260: the constant variable 'std::_BRE_MAX_GRP' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
C:\msvc\binaries\x86chk\inc\regex(1160): warning C5260: the constant variable 'std::_Bmp_max' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
C:\msvc\binaries\x86chk\inc\regex(1161): warning C5260: the constant variable 'std::_Bmp_shift' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
C:\msvc\binaries\x86chk\inc\regex(1162): warning C5260: the constant variable 'std::_Bmp_chrs' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
C:\msvc\binaries\x86chk\inc\regex(1163): warning C5260: the constant variable 'std::_Bmp_mask' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
C:\msvc\binaries\x86chk\inc\regex(1164): warning C5260: the constant variable 'std::_Bmp_size' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
C:\msvc\binaries\x86chk\inc\regex(1167): warning C5260: the constant variable 'std::_ARRAY_THRESHOLD' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it 'inline' as well if it will be shared across translation units, or 'static' to express intent to use it local to this translation unit
  • This fixes all of these occurrences, plus another that I found, _Size_after_ebco_v in <xstring>.
    • I need to detach the comment there due to wrapping.
  • All are potentially C++14, so they need to use _INLINE_VAR.
  • In <regex>, I'm upgrading const to constexpr.
  • In <vector>, I'm adding a newline to avoid = alignment, and because typedefs and constants are different.

@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Jun 15, 2022
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner June 15, 2022 12:03
@StephanTLavavej StephanTLavavej self-assigned this Jun 15, 2022
@StephanTLavavej
Copy link
Member Author

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

@StephanTLavavej StephanTLavavej merged commit ea32e86 into microsoft:main Jun 16, 2022
@StephanTLavavej StephanTLavavej deleted the inline-constexpr branch June 16, 2022 01:35
fsb4000 pushed 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.

2 participants