Skip to content

Commit 533b62d

Browse files
committed
Update [[nodiscard]] default for streaming to match established convention
We already do this for assignment: As with assignment, the convention for streaming operators is to return a reference to the stream, to permit chaining. But ignoring that return value at the end of each chain is always expected and always correct, and so those return values should always be discardable.
1 parent 3fbe27e commit 533b62d

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

regression-tests/test-results/pure2-enum.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ inline constexpr skat_game skat_game::null = 23;
157157
return "invalid skat_game value";
158158
}
159159

160-
[[nodiscard]] auto operator<<(std::ostream& o, cpp2::in<skat_game> val) -> std::ostream&{o << CPP2_UFCS_0(to_string, val);return o; }
160+
auto operator<<(std::ostream& o, cpp2::in<skat_game> val) -> std::ostream&{o << CPP2_UFCS_0(to_string, val);return o; }
161161
#line 15 "pure2-enum.cpp2"
162162
auto duality::flip(cpp2::in<duality> val) & -> void{
163163
if (val == first) {
@@ -199,7 +199,7 @@ inline constexpr duality duality::second = 1;
199199
return "invalid duality value";
200200
}
201201

202-
[[nodiscard]] auto operator<<(std::ostream& o, cpp2::in<duality> val) -> std::ostream&{o << CPP2_UFCS_0(to_string, val);return o; }
202+
auto operator<<(std::ostream& o, cpp2::in<duality> val) -> std::ostream&{o << CPP2_UFCS_0(to_string, val);return o; }
203203
inline constexpr cpp2::u8 file_attributes::enumeration_count = 4;
204204

205205
constexpr file_attributes::file_attributes(auto const& val)
@@ -250,7 +250,7 @@ inline constexpr file_attributes file_attributes::none = 0;
250250
return ret + ")";
251251
}
252252

253-
[[nodiscard]] auto operator<<(std::ostream& o, cpp2::in<file_attributes> val) -> std::ostream&{o << CPP2_UFCS_0(to_string, val);return o; }
253+
auto operator<<(std::ostream& o, cpp2::in<file_attributes> val) -> std::ostream&{o << CPP2_UFCS_0(to_string, val);return o; }
254254
#line 33 "pure2-enum.cpp2"
255255
auto main() -> int{
256256
auto janus {duality::second};

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8923:1630"
1+
"8924:1404"

source/cppfront.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5666,6 +5666,10 @@ class cppfront
56665666
!emit_as_friend // can't have an attribute on a friend declaration-not-definition
56675667
|| printer.get_phase() != printer.phase1_type_defs_func_decls
56685668
)
5669+
&& !(
5670+
n.name()
5671+
&& is_streaming_operator(n.name()->as_string_view())
5672+
)
56695673
)
56705674
{
56715675
printer.print_cpp2( "[[nodiscard]] ", n.position() );

0 commit comments

Comments
 (0)