[Issue 23791] New: Rvalue default argument for ref paramter gives misleading error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 17 15:04:04 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23791

          Issue ID: 23791
           Summary: Rvalue default argument for ref paramter gives
                    misleading error
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

As of DMD 2.102.2, attempting to compile the following program:

---
void f1(ref int n = 123) {}

struct S {}
void f2(ref S s = S.init) {}
---

...produces the following error messages:

---
bug.d(1): Error: cannot modify constant `123`
bug.d(4): Error: `S()` is not an lvalue and cannot be modified
---

These messages are misleading, because the program is not attempting to modify
either `123` or `S()`.

The actual cause of the errors is that rvalues cannot be used as default
arguments for `ref` parameters. The messages should reflect this.

--


More information about the Digitalmars-d-bugs mailing list