Skip to content

Commit 37cf0bf

Browse files
committed
Allow bitwise operators to be nonmembers, see #768
1 parent cdfe121 commit 37cf0bf

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.2.1 Build 8A20:1557
2+
cppfront compiler v0.2.1 Build 8A21:1022
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/build.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"8A20:1557"
1+
"8A21:1022"

source/sema.h

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,36 +1292,24 @@ class sema
12921292
return false;
12931293
}
12941294

1295-
// Require that comparison operators, bitwise binary operators,
1296-
// assignment operators, and comparison operators must be members
1295+
// Require that ~/comparison/assignment operators must be members
12971296
if (
12981297
n.identifier
12991298
&& !n.is_function_with_this()
13001299
&& (
1301-
n.has_name("operator==")
1302-
|| n.has_name("operator!=")
1303-
|| n.has_name("operator<")
1304-
|| n.has_name("operator<=")
1305-
|| n.has_name("operator>")
1306-
|| n.has_name("operator>=")
1307-
|| n.has_name("operator<=>")
1308-
|| n.has_name("operator&")
1309-
|| n.has_name("operator|")
1310-
|| n.has_name("operator^")
1311-
|| n.is_comparison()
1300+
// Note re comparisons: The reason I'm restricting comparisons to be members
1301+
// is because with comparison symmetry (since C++20, derived from Cpp2)
1302+
// there's no longer a need for a type author to write them as nonmembers,
1303+
// and I want to discourage that habit by banning nonmembers. However, there
1304+
// could be a motivation to write them as nonmembers in the case where the
1305+
// type author doesn't provide them -- if that turns out to be important we
1306+
// can remove the restriction on nonmember comparisons here
1307+
n.is_comparison()
1308+
13121309
// The following would be rejected anyway by the Cpp1 compiler,
13131310
// but including them here gives nicer and earlier error messages
13141311
|| n.has_name("operator~")
1315-
|| n.has_name("operator+=")
1316-
|| n.has_name("operator-=")
1317-
|| n.has_name("operator*=")
1318-
|| n.has_name("operator/=")
1319-
|| n.has_name("operator%=")
1320-
|| n.has_name("operator&=")
1321-
|| n.has_name("operator|=")
1322-
|| n.has_name("operator^=")
1323-
|| n.has_name("operator<<=")
1324-
|| n.has_name("operator>>=")
1312+
|| n.is_compound_assignment()
13251313
)
13261314
)
13271315
{

0 commit comments

Comments
 (0)