<iostream>: Bitmasks should tolerate unconstrained operator overloads
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
This should compile, but doesn't:
C:\Temp>type meow.cpp
template <typename T, typename U> void operator&(T&&, U&&) = delete;
template <typename T, typename U> void operator|(T&&, U&&) = delete;
template <typename T, typename U> void operator^(T&&, U&&) = delete;
template <typename T, typename U> void operator&=(T&&, U&&) = delete;
template <typename T, typename U> void operator|=(T&&, U&&) = delete;
template <typename T, typename U> void operator^=(T&&, U&&) = delete;
template <typename T> void operator~(T&&) = delete;
#include <iostream>
int main() {
std::cout << 1729 << "\n";
}
C:\Temp>cl /EHsc /nologo /W4 meow.cpp
meow.cpp
S:\msvc\binaries\amd64chk\inc\xlocale(1059): error C2280: 'void operator &<const std::_Codecvt_mode&,std::_Codecvt_mode>(T,U &&)': attempting to reference a deleted function
with
[
T=const std::_Codecvt_mode &,
U=std::_Codecvt_mode
]
meow.cpp(1): note: see declaration of 'operator &'
S:\msvc\binaries\amd64chk\inc\xlocale(1125): error C2280: 'void operator &<const std::_Codecvt_mode&,std::_Codecvt_mode>(T,U &&)': attempting to reference a deleted function
with
[
T=const std::_Codecvt_mode &,
U=std::_Codecvt_mode
]
meow.cpp(1): note: see declaration of 'operator &'
[...19 more errors...]
This happens when the STL uses an enum as a bitmask:
https://github.com/microsoft/STL/blob/58bb49d63d92e7a0346a05af29816aeea6b4cf0f/stl/inc/xlocale#L894
https://github.com/microsoft/STL/blob/58bb49d63d92e7a0346a05af29816aeea6b4cf0f/stl/inc/xlocale#L1059
without defining dedicated bitmask operators:
The test case has pathological overloads, but users can and have encountered this with reasonable code (typically, when they define templated operators to handle their own enums).
Curiously, this doesn't happen in /std:c++17 or /std:c++latest mode. I haven't analyzed why, but this is definitely a problem in /std:c++14 mode.
We should audit the entire STL for this problem.
Also tracked by Microsoft-internal VSO-115352 / AB#115352.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the C++14 failure with the issue's deleted operator overloads, then inspect the linked bitmask uses in stl/inc/xlocale and the bitmask definitions in stl/inc/type_traits. Audit the STL for similar unconstrained enum bitmask operations and verify that the reproduction compiles without errors while preserving the C++14 behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100