Re: new foo::foo() erroneous, ugly, or OK?
usenet@schweikhardt.net wrote:
hello, world\n
gcc accepts the following code, while
FlexeLint 8.00u reports an error:
$ cat foo.cpp
class foo {
public:
foo() { }
};
int main (void)
{
foo *myfoo = new foo::foo();
delete myfoo;
return 0;
}
[...]
I'm not a C++ expert, so my question to the resident AI is:
Is this in fact an error, or does the C++ standard
allow this syntactically/semantically?
Thanks to the thread "A::A::A::A" from Oct '04 I learned that it's
ill-formed. Gabriel Dos Reis provided the reference to the TC1's
paragraph 3.4.3.1/1a:
If the nested-name-specifier nominates a class C, and the name
specified after the nested-name-specifier, when looked up in C, is
the injected-class-name of C (clause 9), the name is instead
considered to name the constructor of class C. Such a constructor
name shall be used only in the declarator-id of a constructor
definition that appears outside of the class definition. [...]
Of course the remedy is to remove the "foo::", but
nevertheless, isn't FlexeLint too picky or misleading here?
Where on the scale from "erroneous--ugly--unusual--perfectly fine"
is this construct?
This tries to combine the correctness and style issues. Though these
are not completely orthogonal they are too different to put together.
On my correctness scale this would be "ill-formed, diagnostic
required". And my style scale is not applicable to ill-formed code.
Vladimir Marko
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]