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

<iomanip>: consider removing operator>> for istream >> setfill(c) #3724

Closed
achabense opened this issue May 21, 2023 · 4 comments · Fixed by #3725
Closed

<iomanip>: consider removing operator>> for istream >> setfill(c) #3724

achabense opened this issue May 21, 2023 · 4 comments · Fixed by #3725
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@achabense
Copy link
Contributor

achabense commented May 21, 2023

According to the standard(this version), std::setfill is only for ostreams. Therefore, istream >> setfill(c) has no well-defined meaning and can lead to confusion.
image
The following piece of code should get removed.

STL/stl/inc/iomanip

Lines 28 to 35 in a621095

template <class _Elem2, class _Traits>
friend basic_istream<_Elem2, _Traits>& operator>>(basic_istream<_Elem2, _Traits>& _Istr, const _Fillobj& _Manip) {
// set fill character in input stream
static_assert(is_same_v<_Elem, _Elem2>, "wrong character type for setfill");
_Istr.fill(_Manip._Fill);
return _Istr;
}

@achabense achabense changed the title <iomanip>: consider removing istream >> setfill(c) <iomanip>: consider removing operator>> for istream >> setfill(c) May 21, 2023
@fsb4000
Copy link
Contributor

fsb4000 commented May 21, 2023

Thanks. I agree.

I noticed that LLVM libc++ doesn't have the operator. But GCC libstdc++ has the operator.

https://gcc.godbolt.org/z/a6xd65xnY

Will you report this bug to GCC developers?

Or should I do that?

@achabense
Copy link
Contributor Author

@fsb4000 I'm not famaliar with GCC, you may do the report.

@fsb4000
Copy link
Contributor

fsb4000 commented May 21, 2023

@achabense
Copy link
Contributor Author

achabense commented May 21, 2023

It seems also better to define separate classes as return type for get_* and put_*, and give only matching operator<< or >> for each class, to make the following cases directly unavailable.

#include<iostream>
#include<iomanip>

int main() {
	double _{};
	tm __{};

	//compilable, but comfusing and also not specified by the standard.
	std::cout << std::get_money(_);
	std::cout << std::get_time(&__, "");

	//not compilable due to constness. the constraint is too indirect.
	//std::cin >> std::put_money(_);
	//std::cin >> std::put_time(&__, "");
}

@CaseyCarter CaseyCarter added the bug Something isn't working label May 24, 2023
@StephanTLavavej StephanTLavavej added the fixed Something works now, yay! label May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants