Remove D1 operators from the D2 language (#20744)

This commit is contained in:
Dennis 2025-01-20 23:08:05 +01:00 committed by GitHub
parent 2a627016f6
commit fc2b2271a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 271 additions and 336 deletions

View file

@ -8820,59 +8820,15 @@ struct Id final
static Identifier* system;
static Identifier* disable;
static Identifier* _dollar;
static Identifier* uadd;
static Identifier* neg;
static Identifier* com;
static Identifier* add;
static Identifier* add_r;
static Identifier* sub;
static Identifier* sub_r;
static Identifier* mul;
static Identifier* mul_r;
static Identifier* div;
static Identifier* div_r;
static Identifier* mod;
static Identifier* mod_r;
static Identifier* eq;
static Identifier* cmp;
static Identifier* iand;
static Identifier* iand_r;
static Identifier* ior;
static Identifier* ior_r;
static Identifier* ixor;
static Identifier* ixor_r;
static Identifier* shl;
static Identifier* shl_r;
static Identifier* shr;
static Identifier* shr_r;
static Identifier* ushr;
static Identifier* ushr_r;
static Identifier* cat;
static Identifier* cat_r;
static Identifier* assign;
static Identifier* addass;
static Identifier* subass;
static Identifier* mulass;
static Identifier* divass;
static Identifier* modass;
static Identifier* andass;
static Identifier* orass;
static Identifier* xorass;
static Identifier* shlass;
static Identifier* shrass;
static Identifier* ushrass;
static Identifier* catass;
static Identifier* postinc;
static Identifier* postdec;
static Identifier* index;
static Identifier* indexass;
static Identifier* slice;
static Identifier* sliceass;
static Identifier* call;
static Identifier* _cast;
static Identifier* opIn;
static Identifier* opIn_r;
static Identifier* opStar;
static Identifier* opDot;
static Identifier* opDispatch;
static Identifier* opDollar;
@ -8884,9 +8840,6 @@ struct Id final
static Identifier* opOpAssign;
static Identifier* opIndexOpAssign;
static Identifier* opSliceOpAssign;
static Identifier* pow;
static Identifier* pow_r;
static Identifier* powass;
static Identifier* classNew;
static Identifier* classDelete;
static Identifier* apply;

View file

@ -223,59 +223,15 @@ immutable Msgtable[] msgtable =
{ "__LOCAL_SIZE" },
// For operator overloads
{ "uadd", "opPos" },
{ "neg", "opNeg" },
{ "com", "opCom" },
{ "add", "opAdd" },
{ "add_r", "opAdd_r" },
{ "sub", "opSub" },
{ "sub_r", "opSub_r" },
{ "mul", "opMul" },
{ "mul_r", "opMul_r" },
{ "div", "opDiv" },
{ "div_r", "opDiv_r" },
{ "mod", "opMod" },
{ "mod_r", "opMod_r" },
{ "eq", "opEquals" },
{ "cmp", "opCmp" },
{ "iand", "opAnd" },
{ "iand_r", "opAnd_r" },
{ "ior", "opOr" },
{ "ior_r", "opOr_r" },
{ "ixor", "opXor" },
{ "ixor_r", "opXor_r" },
{ "shl", "opShl" },
{ "shl_r", "opShl_r" },
{ "shr", "opShr" },
{ "shr_r", "opShr_r" },
{ "ushr", "opUShr" },
{ "ushr_r", "opUShr_r" },
{ "cat", "opCat" },
{ "cat_r", "opCat_r" },
{ "assign", "opAssign" },
{ "addass", "opAddAssign" },
{ "subass", "opSubAssign" },
{ "mulass", "opMulAssign" },
{ "divass", "opDivAssign" },
{ "modass", "opModAssign" },
{ "andass", "opAndAssign" },
{ "orass", "opOrAssign" },
{ "xorass", "opXorAssign" },
{ "shlass", "opShlAssign" },
{ "shrass", "opShrAssign" },
{ "ushrass", "opUShrAssign" },
{ "catass", "opCatAssign" },
{ "postinc", "opPostInc" },
{ "postdec", "opPostDec" },
{ "index", "opIndex" },
{ "indexass", "opIndexAssign" },
{ "slice", "opSlice" },
{ "sliceass", "opSliceAssign" },
{ "call", "opCall" },
{ "_cast", "opCast" },
{ "opIn" },
{ "opIn_r" },
{ "opStar" },
{ "opDot" },
{ "opDispatch" },
{ "opDollar" },
@ -287,9 +243,6 @@ immutable Msgtable[] msgtable =
{ "opOpAssign" },
{ "opIndexOpAssign" },
{ "opSliceOpAssign" },
{ "pow", "opPow" },
{ "pow_r", "opPow_r" },
{ "powass", "opPowAssign" },
{ "classNew", "new" },
{ "classDelete", "delete" },

View file

@ -112,25 +112,12 @@ private bool isAssignmentOpId(Identifier id)
import dmd.id : Id;
return id == Id.assign
|| id == Id.addass
|| id == Id.subass
|| id == Id.mulass
|| id == Id.divass
|| id == Id.modass
|| id == Id.andass
|| id == Id.orass
|| id == Id.xorass
|| id == Id.shlass
|| id == Id.shrass
|| id == Id.ushrass
|| id == Id.catass
|| id == Id.indexass
|| id == Id.slice
|| id == Id.sliceass
|| id == Id.opOpAssign
|| id == Id.opIndexOpAssign
|| id == Id.opSliceOpAssign
|| id == Id.powass;
|| id == Id.opSliceOpAssign;
}
/**

View file

@ -71,84 +71,6 @@ bool isCommutative(EXP op) @safe
return false;
}
/***********************************
* Get Identifier for operator overload.
*/
private Identifier opId(Expression e)
{
switch (e.op)
{
case EXP.uadd: return Id.uadd;
case EXP.negate: return Id.neg;
case EXP.tilde: return Id.com;
case EXP.cast_: return Id._cast;
case EXP.in_: return Id.opIn;
case EXP.plusPlus: return Id.postinc;
case EXP.minusMinus: return Id.postdec;
case EXP.add: return Id.add;
case EXP.min: return Id.sub;
case EXP.mul: return Id.mul;
case EXP.div: return Id.div;
case EXP.mod: return Id.mod;
case EXP.pow: return Id.pow;
case EXP.leftShift: return Id.shl;
case EXP.rightShift: return Id.shr;
case EXP.unsignedRightShift: return Id.ushr;
case EXP.and: return Id.iand;
case EXP.or: return Id.ior;
case EXP.xor: return Id.ixor;
case EXP.concatenate: return Id.cat;
case EXP.assign: return Id.assign;
case EXP.addAssign: return Id.addass;
case EXP.minAssign: return Id.subass;
case EXP.mulAssign: return Id.mulass;
case EXP.divAssign: return Id.divass;
case EXP.modAssign: return Id.modass;
case EXP.powAssign: return Id.powass;
case EXP.leftShiftAssign: return Id.shlass;
case EXP.rightShiftAssign: return Id.shrass;
case EXP.unsignedRightShiftAssign: return Id.ushrass;
case EXP.andAssign: return Id.andass;
case EXP.orAssign: return Id.orass;
case EXP.xorAssign: return Id.xorass;
case EXP.concatenateAssign: return Id.catass;
case EXP.equal: return Id.eq;
case EXP.lessThan:
case EXP.lessOrEqual:
case EXP.greaterThan:
case EXP.greaterOrEqual: return Id.cmp;
case EXP.array: return Id.index;
case EXP.star: return Id.opStar;
default: assert(0);
}
}
/***********************************
* Get Identifier for reverse operator overload,
* `null` if not supported for this operator.
*/
private Identifier opId_r(Expression e)
{
switch (e.op)
{
case EXP.in_: return Id.opIn_r;
case EXP.add: return Id.add_r;
case EXP.min: return Id.sub_r;
case EXP.mul: return Id.mul_r;
case EXP.div: return Id.div_r;
case EXP.mod: return Id.mod_r;
case EXP.pow: return Id.pow_r;
case EXP.leftShift: return Id.shl_r;
case EXP.rightShift: return Id.shr_r;
case EXP.unsignedRightShift:return Id.ushr_r;
case EXP.and: return Id.iand_r;
case EXP.or: return Id.ior_r;
case EXP.xor: return Id.ixor_r;
case EXP.concatenate: return Id.cat_r;
default: return null;
}
}
/*******************************************
* Helper function to turn operator into template argument list
*/
@ -400,19 +322,7 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
result = result.expressionSemantic(sc);
return result;
}
// D1-style operator overloads, deprecated
if (e.op != EXP.prePlusPlus && e.op != EXP.preMinusMinus)
{
auto id = opId(e);
fd = search_function(ad, id);
if (fd)
{
// @@@DEPRECATED_2.110@@@.
// Deprecated in 2.088, made an error in 2.100
error(e.loc, "`%s` is obsolete. Use `opUnary(string op)() if (op == \"%s\")` instead.", id.toChars(), EXPtoString(e.op).ptr);
return ErrorExp.get();
}
}
// Didn't find it. Forward to aliasthis
if (ad.aliasthis && !isRecursiveAliasThis(att, e.e1.type))
{
@ -610,8 +520,6 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
Expression visitBin(BinExp e)
{
//printf("BinExp::op_overload() (%s)\n", e.toChars());
Identifier id = opId(e);
Identifier id_r = opId_r(e);
int argsset = 0;
AggregateDeclaration ad1 = isAggregate(e.e1.type);
AggregateDeclaration ad2 = isAggregate(e.e2.type);
@ -638,6 +546,8 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
if (ad1 && search_function(ad1, Id.opUnary))
return null;
}
Identifier id = e.op == EXP.assign ? Id.assign : null;
Identifier id_r = null;
if (e.op != EXP.equal && e.op != EXP.notEqual && e.op != EXP.assign && e.op != EXP.plusPlus && e.op != EXP.minusMinus)
{
/* Try opBinary and opBinaryRight
@ -678,12 +588,6 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
s = search_function(ad1, id);
if (s && id != Id.assign)
{
// @@@DEPRECATED_2.110@@@.
// Deprecated in 2.088, made an error in 2.100
if (id == Id.postinc || id == Id.postdec)
error(e.loc, "`%s` is obsolete. Use `opUnary(string op)() if (op == \"%s\")` instead.", id.toChars(), EXPtoString(e.op).ptr);
else
error(e.loc, "`%s` is obsolete. Use `opBinary(string op)(...) if (op == \"%s\")` instead.", id.toChars(), EXPtoString(e.op).ptr);
return ErrorExp.get();
}
}
@ -1201,7 +1105,6 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
{
return ErrorExp.get();
}
Identifier id = opId(e);
Expressions* args2 = new Expressions();
AggregateDeclaration ad1 = isAggregate(e.e1.type);
Dsymbol s = null;
@ -1218,6 +1121,7 @@ Expression op_overload(Expression e, Scope* sc, EXP* pop = null)
}
}
// Set tiargs, the template argument list, which will be the operator string
Identifier id;
if (s)
{
id = Id.opOpAssign;

View file

@ -1,52 +1,93 @@
/*
REQUIRED_ARGS: -de
REQUIRED_ARGS:
TEST_OUTPUT:
---
fail_compilation/dep_d1_ops.d(105): Error: `opAdd` is obsolete. Use `opBinary(string op)(...) if (op == "+")` instead.
fail_compilation/dep_d1_ops.d(106): Error: `opAdd_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == "+")` instead.
fail_compilation/dep_d1_ops.d(107): Error: `opSub` is obsolete. Use `opBinary(string op)(...) if (op == "-")` instead.
fail_compilation/dep_d1_ops.d(108): Error: `opSub_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == "-")` instead.
fail_compilation/dep_d1_ops.d(109): Error: `opMul` is obsolete. Use `opBinary(string op)(...) if (op == "*")` instead.
fail_compilation/dep_d1_ops.d(110): Error: `opMul_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == "*")` instead.
fail_compilation/dep_d1_ops.d(111): Error: `opDiv` is obsolete. Use `opBinary(string op)(...) if (op == "/")` instead.
fail_compilation/dep_d1_ops.d(112): Error: `opDiv_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == "/")` instead.
fail_compilation/dep_d1_ops.d(113): Error: `opMod` is obsolete. Use `opBinary(string op)(...) if (op == "%")` instead.
fail_compilation/dep_d1_ops.d(114): Error: `opMod_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == "%")` instead.
fail_compilation/dep_d1_ops.d(116): Error: `opAnd` is obsolete. Use `opBinary(string op)(...) if (op == "&")` instead.
fail_compilation/dep_d1_ops.d(117): Error: `opOr` is obsolete. Use `opBinary(string op)(...) if (op == "|")` instead.
fail_compilation/dep_d1_ops.d(118): Error: `opXor` is obsolete. Use `opBinary(string op)(...) if (op == "^")` instead.
fail_compilation/dep_d1_ops.d(120): Error: `opShl` is obsolete. Use `opBinary(string op)(...) if (op == "<<")` instead.
fail_compilation/dep_d1_ops.d(121): Error: `opShl_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == "<<")` instead.
fail_compilation/dep_d1_ops.d(122): Error: `opShr` is obsolete. Use `opBinary(string op)(...) if (op == ">>")` instead.
fail_compilation/dep_d1_ops.d(123): Error: `opShr_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == ">>")` instead.
fail_compilation/dep_d1_ops.d(124): Error: `opUShr` is obsolete. Use `opBinary(string op)(...) if (op == ">>>")` instead.
fail_compilation/dep_d1_ops.d(125): Error: `opUShr_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == ">>>")` instead.
fail_compilation/dep_d1_ops.d(127): Error: `opCat` is obsolete. Use `opBinary(string op)(...) if (op == "~")` instead.
fail_compilation/dep_d1_ops.d(128): Error: `opCat_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == "~")` instead.
fail_compilation/dep_d1_ops.d(130): Error: `opNeg` is obsolete. Use `opUnary(string op)() if (op == "-")` instead.
fail_compilation/dep_d1_ops.d(131): Error: `opCom` is obsolete. Use `opUnary(string op)() if (op == "~")` instead.
fail_compilation/dep_d1_ops.d(132): Error: `opPostInc` is obsolete. Use `opUnary(string op)() if (op == "++")` instead.
fail_compilation/dep_d1_ops.d(133): Error: `opPostDec` is obsolete. Use `opUnary(string op)() if (op == "--")` instead.
fail_compilation/dep_d1_ops.d(134): Error: `opStar` is obsolete. Use `opUnary(string op)() if (op == "*")` instead.
fail_compilation/dep_d1_ops.d(136): Error: `opIn` is obsolete. Use `opBinary(string op)(...) if (op == "in")` instead.
fail_compilation/dep_d1_ops.d(137): Error: `opIn_r` is obsolete. Use `opBinaryRight(string op)(...) if (op == "in")` instead.
fail_compilation/dep_d1_ops.d(139): Error: `opAddAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "+")` instead.
fail_compilation/dep_d1_ops.d(140): Error: `opSubAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "-")` instead.
fail_compilation/dep_d1_ops.d(141): Error: `opMulAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "*")` instead.
fail_compilation/dep_d1_ops.d(142): Error: `opDivAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "/")` instead.
fail_compilation/dep_d1_ops.d(143): Error: `opModAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "%")` instead.
fail_compilation/dep_d1_ops.d(144): Error: `opAndAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "&")` instead.
fail_compilation/dep_d1_ops.d(145): Error: `opOrAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "|")` instead.
fail_compilation/dep_d1_ops.d(146): Error: `opXorAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "^")` instead.
fail_compilation/dep_d1_ops.d(147): Error: `opShlAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "<<")` instead.
fail_compilation/dep_d1_ops.d(148): Error: `opShrAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == ">>")` instead.
fail_compilation/dep_d1_ops.d(149): Error: `opUShrAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == ">>>")` instead.
fail_compilation/dep_d1_ops.d(150): Error: `opCatAssign` is obsolete. Use `opOpAssign(string op)(...) if (op == "~")` instead.
fail_compilation/dep_d1_ops.d(158): Error: `opCom` is obsolete. Use `opUnary(string op)() if (op == "~")` instead.
fail_compilation/dep_d1_ops.d(198): Error: incompatible types for `(s) + (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(199): Error: incompatible types for `(1) + (s)`: `int` and `S`
fail_compilation/dep_d1_ops.d(200): Error: incompatible types for `(s) - (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(201): Error: incompatible types for `(1) - (s)`: `int` and `S`
fail_compilation/dep_d1_ops.d(202): Error: incompatible types for `(s) * (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(203): Error: incompatible types for `(1) * (s)`: `int` and `S`
fail_compilation/dep_d1_ops.d(204): Error: incompatible types for `(s) / (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(205): Error: incompatible types for `(1) / (s)`: `int` and `S`
fail_compilation/dep_d1_ops.d(206): Error: incompatible types for `(s) % (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(207): Error: incompatible types for `(1) % (s)`: `int` and `S`
fail_compilation/dep_d1_ops.d(209): Error: incompatible types for `(s) & (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(210): Error: incompatible types for `(s) | (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(211): Error: incompatible types for `(s) ^ (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(213): Error: `s` is not of integral type, it is a `S`
fail_compilation/dep_d1_ops.d(214): Error: `s` is not of integral type, it is a `S`
fail_compilation/dep_d1_ops.d(215): Error: `s` is not of integral type, it is a `S`
fail_compilation/dep_d1_ops.d(216): Error: `s` is not of integral type, it is a `S`
fail_compilation/dep_d1_ops.d(217): Error: `s` is not of integral type, it is a `S`
fail_compilation/dep_d1_ops.d(218): Error: `s` is not of integral type, it is a `S`
fail_compilation/dep_d1_ops.d(220): Error: incompatible types for `(s) ~ (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(221): Error: incompatible types for `(1) ~ (s)`: `int` and `S`
fail_compilation/dep_d1_ops.d(223): Error: operator `+` is not defined for `s` of type `S`
fail_compilation/dep_d1_ops.d(224): Error: operator `-` is not defined for `s` of type `S`
fail_compilation/dep_d1_ops.d(225): Error: `s` is not of integral type, it is a `S`
fail_compilation/dep_d1_ops.d(226): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(227): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(228): Error: can only `*` a pointer, not a `S`
fail_compilation/dep_d1_ops.d(230): Error: incompatible types for `(s) in (1)`: `S` and `int`
fail_compilation/dep_d1_ops.d(231): Error: incompatible types for `(1) in (s)`: `int` and `S`
fail_compilation/dep_d1_ops.d(233): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(234): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(235): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(236): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(237): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(238): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(239): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(240): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(241): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(242): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(243): Error: `s` is not a scalar, it is a `S`
fail_compilation/dep_d1_ops.d(244): Error: cannot append type `int` to type `S`
fail_compilation/dep_d1_ops.d(248): Error: incompatible types for `(c) + (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(249): Error: incompatible types for `(1) + (c)`: `int` and `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(250): Error: incompatible types for `(c) - (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(251): Error: incompatible types for `(1) - (c)`: `int` and `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(252): Error: incompatible types for `(c) * (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(253): Error: incompatible types for `(1) * (c)`: `int` and `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(254): Error: incompatible types for `(c) / (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(255): Error: incompatible types for `(1) / (c)`: `int` and `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(256): Error: incompatible types for `(c) % (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(257): Error: incompatible types for `(1) % (c)`: `int` and `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(259): Error: incompatible types for `(c) & (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(260): Error: incompatible types for `(c) | (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(261): Error: incompatible types for `(c) ^ (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(263): Error: `c` is not of integral type, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(264): Error: `c` is not of integral type, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(265): Error: `c` is not of integral type, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(266): Error: `c` is not of integral type, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(267): Error: `c` is not of integral type, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(268): Error: `c` is not of integral type, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(270): Error: incompatible types for `(c) ~ (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(271): Error: incompatible types for `(1) ~ (c)`: `int` and `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(273): Error: operator `+` is not defined for `c` of type `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(274): Error: operator `-` is not defined for `c` of type `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(275): Error: `c` is not of integral type, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(276): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(277): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(278): Error: can only `*` a pointer, not a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(280): Error: incompatible types for `(c) in (1)`: `dep_d1_ops.C` and `int`
fail_compilation/dep_d1_ops.d(281): Error: incompatible types for `(1) in (c)`: `int` and `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(283): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(284): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(285): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(286): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(287): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(288): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(289): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(290): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(291): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(292): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(293): Error: `c` is not a scalar, it is a `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(294): Error: cannot append type `int` to type `dep_d1_ops.C`
fail_compilation/dep_d1_ops.d(303): Error: `nd` is not of integral type, it is a `dep_d1_ops.NoDeprecation`
---
*/
#line 50
struct S
{
int opAdd(int i) { return 0; }
@ -74,6 +115,58 @@ struct S
int opCat(int i) { return 0; }
int opCat_r(int i) { return 0; }
int opPos() { return 0; }
int opNeg() { return 0; }
int opCom() { return 0; }
int opPostInc() { return 0; }
int opPostDec() { return 0; }
int opStar() { return 0; }
int opIn(int i) { return 0; }
int opIn_r(int i) { return 0; }
int opAddAssign(int i) { return 0; }
int opSubAssign(int i) { return 0; }
int opMulAssign(int i) { return 0; }
int opDivAssign(int i) { return 0; }
int opModAssign(int i) { return 0; }
int opAndAssign(int i) { return 0; }
int opOrAssign(int i) { return 0; }
int opXorAssign(int i) { return 0; }
int opShlAssign(int i) { return 0; }
int opShrAssign(int i) { return 0; }
int opUShrAssign(int i) { return 0; }
int opCatAssign(int i) { return 0; }
}
class C
{
int opAdd(int i) { return 0; }
int opAdd_r(int i) { return 0; }
int opSub(int i) { return 0; }
int opSub_r(int i) { return 0; }
int opMul(int i) { return 0; }
int opMul_r(int i) { return 0; }
int opDiv(int i) { return 0; }
int opDiv_r(int i) { return 0; }
int opMod(int i) { return 0; }
int opMod_r(int i) { return 0; }
int opAnd(int i) { return 0; }
int opOr(int i) { return 0; }
int opXor(int i) { return 0; }
int opShl(int i) { return 0; }
int opShl_r(int i) { return 0; }
int opShr(int i) { return 0; }
int opShr_r(int i) { return 0; }
int opUShr(int i) { return 0; }
int opUShr_r(int i) { return 0; }
int opCat(int i) { return 0; }
int opCat_r(int i) { return 0; }
int opPos() { return 0; }
int opNeg() { return 0; }
int opCom() { return 0; }
int opPostInc() { return 0; }
@ -99,9 +192,9 @@ struct S
void main()
{
S s;
int i;
{
S s;
i = s + 1;
i = 1 + s;
i = s - 1;
@ -127,6 +220,7 @@ void main()
i = s ~ 1;
i = 1 ~ s;
i = +s;
i = -s;
i = ~s;
s++;
@ -148,6 +242,57 @@ void main()
s >>= 1;
s >>>= 1;
s ~= 1;
}
{
C c;
i = c + 1;
i = 1 + c;
i = c - 1;
i = 1 - c;
i = c * 1;
i = 1 * c;
i = c / 1;
i = 1 / c;
i = c % 1;
i = 1 % c;
i = c & 1;
i = c | 1;
i = c ^ 1;
i = c << 1;
i = 1 << c;
i = c >> 1;
i = 1 >> c;
i = c >>> 1;
i = 1 >>> c;
i = c ~ 1;
i = 1 ~ c;
i = +c;
i = -c;
i = ~c;
c++;
c--;
i = *c;
i = c in 1;
i = 1 in c;
c += 1;
c -= 1;
c *= 1;
c /= 1;
c %= 1;
c &= 1;
c |= 1;
c ^= 1;
c <<= 1;
c >>= 1;
c >>>= 1;
c ~= 1;
}
scope nd = new NoDeprecation;
assert((42 in nd) == 0);

View file

@ -0,0 +1,25 @@
// https://issues.dlang.org/show_bug.cgi?id=14343
/* TEST_OUTPUT:
---
fail_compilation/fail14343.d(21): Error: cannot modify struct instance `s` of type `S14343b` because it contains `const` or `immutable` members
fail_compilation/fail14343.d(23): Error: cannot modify struct instance `s` of type `S14343b` because it contains `const` or `immutable` members
---
*/
struct S14343b
{
int i;
immutable(Object) o;
void opAddAssign(int j) { i += j; }
void opAssign(S14343b other) {}
}
void test14343()
{
S14343b s;
++s;
assert(s.i == 1);
s++;
assert(s.i == 2);
}

View file

@ -2,29 +2,13 @@
RUN_OUTPUT:
---
i = 1
Writer.opShl(char[])
BinaryWriter.opShl(int)
a + 1 = 2
1 + a = 2
a + b = 3
b + a = 3
i = 64
12
534
A::opShl(int 4)
4A::opShl(char[])
A::opShl(int 12)
12A::opShl(char[])
B::opShl_r(A)
Success
---
*/
// Test operator overloading
// Ignore deprecation warnings for D1 style operator overloading
// TRANSFORM_OUTPUT: remove_lines("Deprecation: `op")
import core.stdc.stdio;
/**************************************/
@ -995,7 +979,6 @@ struct S14343b
}
void test14343()
{
{
S14343a s, t;
@ -1003,14 +986,6 @@ void test14343()
++s; // OK
s++; // OK <- Error: cannot modify struct s S with immutable members
}
{
S14343b s;
++s;
assert(s.i == 1);
s++;
assert(s.i == 2);
}
}
/**************************************/
// https://issues.dlang.org/show_bug.cgi?id=14344
@ -1081,20 +1056,13 @@ void test20475()
/**************************************/
int main()
{
test1();
test2();
test3();
test4();
test5();
test6();
test7();
test8();
test9();
test10();
test11();
test12();
test13();
test14();
test15();
test1547();
test4953a();

View file

@ -4091,30 +4091,30 @@ void test4258() {
struct Foo4258 {
// binary ++/--
int opPostInc()() if (false) { return 0; }
int opUnary(string op)() if (false) { return 0; }
// binary 1st
int opAdd(R)(R rhs) if (false) { return 0; }
int opAdd_r(R)(R rhs) if (false) { return 0; }
int opBinary(string op, R)(R rhs) if (false) { return 0; }
int opBinaryRight(string op, R)(R rhs) if (false) { return 0; }
// compare
int opCmp(R)(R rhs) if (false) { return 0; }
int opCmp(R)(const(R) rhs) const if (false) { return 0; }
// binary-op assign
int opAddAssign(R)(R rhs) if (false) { return 0; }
int opOpAssign(string op, R)(R rhs) if (false) { return 0; }
}
struct Bar4258 {
// binary commutive 1
int opAdd_r(R)(R rhs) if (false) { return 0; }
int opBinary(string op, R)(R rhs) if (false) { return 0; }
// binary-op assign
int opOpAssign(string op, R)(R rhs) if (false) { return 0; }
}
struct Baz4258 {
// binary commutive 2
int opAdd(R)(R rhs) if (false) { return 0; }
int opBinaryRight(string op, R)(R rhs) if (false) { return 0; }
}
static assert(!is(typeof(Foo4258.init++)));
static assert(!is(typeof(++Foo4258.init)));
static assert(!is(typeof(Foo4258.init + 1)));
static assert(!is(typeof(1 + Foo4258.init)));
static assert(!is(typeof(Foo4258.init < Foo4258.init)));