[Issue 14854] New: @disable this inconsistent between structs and classes
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Jul 31 21:55:59 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14854
Issue ID: 14854
Summary: @disable this inconsistent between structs and classes
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: minor
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: issues.dlang at jmdavisProg.com
This code
class C1
{
@disable this() {}
}
class C2
{
@disable this();
}
struct S1
{
@disable this() {}
}
struct S2
{
@disable this();
}
void main()
{
}
results in this compilation error:
q.d(13): Error: constructor q.S1.this default constructor for structs only
allowed with @disable and no body
For structs, it's clearly required that @disable this() not have a body,
whereas for classes, for some reason, the compiler doesn't care. The error
message does explicitly use the word struct, which implies that this difference
is intentional, but I don't see any reason to allow for the inconsistency. It
just makes it less obvious, which syntax you should be using.
And in general, I don't see any reason to allow bodies on @disabled functions.
One interesting side effect of putting a body on the @disabled default
constructor on a class is that it actually affects the code coverage analyzer,
because the lines inside the body never run and count as uncovered.
So, I suggest that we deprecate having bodies on _all_ @disabled functions and
move to making it an error like it is with @disabling the init property on a
struct.
--
More information about the Digitalmars-d-bugs
mailing list