Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit warning for identifiers starting with __ #19450

Open
dlangBugzillaToGithub opened this issue Jun 26, 2018 · 1 comment
Open

Emit warning for identifiers starting with __ #19450

dlangBugzillaToGithub opened this issue Jun 26, 2018 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

dayllenger reported this on 2018-06-26T08:31:41Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=19028

CC List

Description

Identifiers starting with `__` are reserved for compiler and their behaviour is implementation-defined. But compilers do not show warning or error message when you try to use such names. Furthermore, some functions ignore these identifiers and may produce hidden bugs in a code. For example:

void main()
{
    writeln([__traits(allMembers, S)]); // will print only ["a"]
}

struct S
{
    int a;
    int __refCount;
}

Documentation of `allMembers` says nothing about this behaviour.

Links:
https://dlang.org/spec/lex.html#identifiers
https://dlang.org/spec/traits.html#allMembers
https://github.com/dlang/dmd/blob/2ce74fc1180a3b0ed5e5c29aa79bf3773af5d5b7/src/dmd/traits.d#L1385
https://forum.dlang.org/thread/yauflbmphapnnksckksu@forum.dlang.org
@dlangBugzillaToGithub
Copy link
Author

schveiguy (@schveiguy) commented on 2018-06-26T14:35:39Z

My suggestion is to only emit warnings for packages that are not owned by the language. In other words, the language should be free to add these types of symbols in std.*, rt.*, core.*, and object without complaint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant