Summary: Improve error message for wrong constructor name?
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-09-30 13:14:17 PDT ---
This is born from a post in D.learn:

In code written by D programmers coming from C++ or some other languages, or in
D code translated from other languages, constructors may have the same name of
the struct/union/class (it's a bug):

struct Foo {
     Foo(int x_) {}
void main() {}

DMD 2.049 prints (similar errors are produced if Foo is a class or union):

test.d(2): found 'int' when expecting ')'
test.d(2): no identifier for declarator Foo
test.d(2): semicolon expected, not 'x_'
test.d(2): no identifier for declarator x_
test.d(2): semicolon expected, not ')'
test.d(2): Declaration expected, not ')'
test.d(5): } expected following member declarations in aggregate

In this situation it's positive to give a single error message that is more
easy to understand. To do this well I think DMD has to essentially recognize
that as a Java-style constructor syntax, and refuse it, with a single error
similar to:

test.d(3): class/struct/union constructors are always named 'this' not 'Foo'.

But I am not sure, because the creation of such test may have some negative
side effects. If such side effects are too much bad, then it's better to not
add this test and error message and it's better to close this enhancement

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to