Style: preferring parentheses to '=' for initialization?

V

Victor Bazarov

Tomás said:
Victor Bazarov posted:


That's entirely just a perspective, a point of view, a way of looking
at things. Many more people would say, "It's a member function whose
name is identical to that of the class."

"Many more"? Really? Too bad. They will all be wrong. See 12.1.
The very beginning.
Does the Standard make a distinction between a "call" and an
"invocation"? If it does, I wasn't aware of it, but I'll be more than
happy to change my use of language from here on in if so.

The Standard makes a point of using passive voice every time "call"
and "constructor" happen to be close-by.
SO? Never seen that abbreviation before; could you explain it please?
Anyway, I speak Irish at home.

Significant Other. Security Officer. Saddened Outcast. Salty
Omelette. Who cares? You know whom or what you're talking to when
you're at home.
[..] I think I finally understand the crux of this argument -- are
you basing your stance on the distinction between a "call" and an
"invocation"?

No. Open the Standard and read all there is about constructors.

V
 
V

Victor Bazarov

Tomás said:
[..] He may
also be suggesting that the argument is centered more on stubbornness
to change one's viewpoint, rather than logic.

Very likely.
[..]
If someone said to me: "You can't call a constructor explicitly", then
I'd show them "placement new".

Yes. Exactly as I feared. No hope here.
 
K

Kai-Uwe Bux

mlimber said:
Kai-Uwe Bux said:
Victor said:
Tomás wrote: [snip]
If any novice would like to call a constructor:

[...more confusion...] [snip]

If you need a good explanation about why it's not possible to call
a constructor, please refer to news archives, that topic has been
covered extensively.

Yes, and it appears to be a religious war in which you happen to be on
one side. The issue is far less clear cut than you imply. The standard
itself uses the terminology that a constructor "is called" (although it
does not say by whom). Sometimes, but not always, the phrase is qualified
as "is implicitly called".

I don't see this as contradicting Victor's point: a constructor can be
called but not *directly* by the user -- it can only be implicitly
invoked.

From the standard [12.1/13]:

"Note: explicit constructor calls do not yield lvalues, see 3.10"

Thus, the standard knows something named "explicit constructor call". If you
want to say all *explicit* constructor calls are just *implicit*
invocations of constructors, so be it. I leave it for anybody to decide,
which terminological proposal is causing possible confusion.

All I wanted to point out is that the issue is not clear-cut; the standard
is very explicit about constructors not having names and thus not being
found through name lookup. However, I think it does not provide clear
enough a definition of the word "call" that would allow us to deduce from
the lack of names that constructors cannot be called. All that follows, as
far as I see, is that if a constructor was called (if at all possible),
this call would not qualify as a function call as described in [5.2.2].
However, that leaves the possibility that the standard knows two kinds of
calls: "constructor calls" and "function calls".


Best

Kai-Uwe Bux
 
V

Victor Bazarov

Kai-Uwe Bux said:
mlimber said:
Kai-Uwe Bux said:
Victor Bazarov wrote:

Tomás wrote:
[snip]
If any novice would like to call a constructor:

[...more confusion...]
[snip]

If you need a good explanation about why it's not possible to call
a constructor, please refer to news archives, that topic has been
covered extensively.

Yes, and it appears to be a religious war in which you happen to be
on one side. The issue is far less clear cut than you imply. The
standard itself uses the terminology that a constructor "is called"
(although it does not say by whom). Sometimes, but not always, the
phrase is qualified as "is implicitly called".

I don't see this as contradicting Victor's point: a constructor can
be called but not *directly* by the user -- it can only be implicitly
invoked.

From the standard [12.1/13]:

"Note: explicit constructor calls do not yield lvalues, see 3.10"

Thus, the standard knows something named "explicit constructor call".
If you want to say all *explicit* constructor calls are just
*implicit* invocations of constructors, so be it. I leave it for
anybody to decide, which terminological proposal is causing possible
confusion.

Are you doing this on purpose? I wonder. The same paragraph, the first
"Note" says, ...(do you want to do the honours or should I?)... Never
mind. It says, "[Note: The syntax looks like an explicit call of the
constructor. ]" _LOOKS_LIKE_. Meaning: it is NOT. The other note, the
one you quoted, should not contain the text it contains. It's an apparent
defect. The paragraph talks about "A functional notation type conversion"
and not a call to a contructor.

Besides, those two things are "notes", and they are not normative, as I
am sure you're aware.

I am going to ask about it in comp.std.c++. Now.

V
 
K

Kai-Uwe Bux

Victor said:
Kai-Uwe Bux said:
Victor said:
Tomás wrote: [snip]
If any novice would like to call a constructor:

[...more confusion...] [snip]

If you need a good explanation about why it's not possible to call
a constructor, please refer to news archives, that topic has been
covered extensively.

Yes, and it appears to be a religious war in which you happen to be
on one side.

Pardon me, but why did you use the term "religious"? What's religious
about it?

I think the phrase "religious war" in the context of news groups has a
meaning that does not derive immediately from its components. What is going
on here is of course neither religious nor a war (I least, I would hope
so).

It would have to be a really compelling reason to change side in this
issue. Do you have a reason to state?

Yes; but I am sure, I cannot say anything that you have not heard before.


Best

Kai-Uwe Bux
 
N

Noah Roberts

mlimber said:
I don't see this as contradicting Victor's point: a constructor can be
called but not *directly* by the user -- it can only be implicitly
invoked.

What exactly is a call if it is not an invocation?

Invoke a procedure, call a procedure...the diff?

Invoke a constructor, call a constructor...again, the diff?

This "please protect the newbies" argument is even sillier than most.
 
K

Kai-Uwe Bux

Victor said:
Kai-Uwe Bux wrote: [snip]
From the standard [12.1/13]:

"Note: explicit constructor calls do not yield lvalues, see 3.10"

Thus, the standard knows something named "explicit constructor call".
If you want to say all *explicit* constructor calls are just
*implicit* invocations of constructors, so be it. I leave it for
anybody to decide, which terminological proposal is causing possible
confusion.

Are you doing this on purpose? I wonder.

Of course:)
The same paragraph, the first
"Note" says, ...(do you want to do the honours or should I?)... Never
mind. It says, "[Note: The syntax looks like an explicit call of the
constructor. ]" _LOOKS_LIKE_. Meaning: it is NOT. The other note, the
one you quoted, should not contain the text it contains. It's an apparent
defect. The paragraph talks about "A functional notation type conversion"
and not a call to a contructor.

Ok, you could call that a defect. All I wanted to point out is that the
standard does not always follow your linguistic intuitions.

I can see your point: there are function calls and the standard goes on and
has lots of useful things to say about them. Now, one can make the proposal
to use "call" only when there is a function call to emphasize the
difference of functions and constructors; and I can see the merits of such
a proposal.

However, I do not see that the standard defines "call" (as opposed to
function call) that narrowly. If it does not then there is a possibility
that other calls exist in C++. What is your reason to assume that they
don't, given that the standard mentions at least "explicit constructor
calls"?

Or do you just want to say: those other calls *should* not exist and the
standard *should* be rewritten accordingly? (After all, rewriting
constructor calls out of existence would not change the observable behavior
of any C++ program).

Besides, those two things are "notes", and they are not normative, as I
am sure you're aware.

For what we are discussing, they don't have to be normative. Only stuff that
is needed to determine the observable behavior of a program or the
diagnostics required by a compiler needs to be normative. Which terminology
is appropriate for discussing C++ in news groups should be ruled by: which
terminology is useful to make heads and tails of the standard as a whole.


Best

Kai-Uwe Bux
 
M

mlimber

Noah said:
What exactly is a call if it is not an invocation?

Invoke a procedure, call a procedure...the diff?

Invoke a constructor, call a constructor...again, the diff?

"Call" and "invoke" are synonymous. The difference we're talking about
is the ability to call something explicitly -- ordinary functions you
can, destructors you can, but constructors you cannot.
This "please protect the newbies" argument is even sillier than most.

Well, I agree that it's not really that important of a distinction in
most circumstances and thinking the wrong way won't lead too many
astray, but it remains a valid distinction nonetheless.

Cheers! --M
 
A

Alf P. Steinbach

* Victor Bazarov:
Tomás said:
Victor Bazarov posted:
Tomás wrote:
[..]
If I'm dealing with a Fancy Class Type, then I use the parentheses
method. It makes more sense because you're calling a constructor
Please don't confuse newbies with improper terminology. You're not
"calling a constructor". You're constructing (and initialising)
an object.

I didn't think he was a newbie (he refers to his "colleagues" multiple
times). I figured he was an experienced C++ programmer who put his
doctrine book down for a few minutes to think for himself.

I wasn't talking about the OP. Newbies read this newsgroup too, if you
didn't know. They will see your post and decide that it's possible to
"call a constructor". If you wanted to communicate to the OP exclusively,
use private e-mail.

It is of course possible to call a constructor, explicitly or implicitly.

An explicit constructor call is not an lvalue, according to the standard.

A default constructor is a constructor that can be called without
arguments, according to the standard.
 
T

Tomás

Alf P. Steinbach posted:
It is of course possible to call a constructor, explicitly or
implicitly.

An explicit constructor call is not an lvalue, according to the
standard.

A default constructor is a constructor that can be called without
arguments, according to the standard.


This is great fun!


(1) Implicit:

int main()
{
std::string local_object;
}


(2) Explicit:


int main()
{
new( some_global_buffer ) std::string;
}


-Tomás
 
V

Victor Bazarov

Alf said:
[...]
It is of course possible to call a constructor, explicitly or
implicitly.
An explicit constructor call is not an lvalue, according to the
standard.

We'll see about that, after I get a reply in comp.std.c++.

V
 
A

Alf P. Steinbach

* Tomás:
Alf P. Steinbach posted:



This is great fun!


(1) Implicit:

int main()
{
std::string local_object;
}

Yep.


(2) Explicit:


int main()
{
new( some_global_buffer ) std::string;
}

If I understand what you mean correctly, namely placement new, then no,
that's not the explicit constructor call that isn't an lvalue.

Although any new expression for class type, whether placment or not, is
in a sense an explicit constructor call, and doesn't yield an lvalue.

string() is an explicit constructor call: the result is not an lvalue.
 
N

Noah Roberts

Victor said:
Are you doing this on purpose? I wonder. The same paragraph, the first
"Note" says, ...(do you want to do the honours or should I?)... Never
mind. It says, "[Note: The syntax looks like an explicit call of the
constructor. ]" _LOOKS_LIKE_. Meaning: it is NOT.

You are cheating here. That section is about functional notation type
conversions and that is what the note you are refering to is talking
about. The entire quote actually makes the meaning quite clear that
there is such a thing as explicit constructor calls but these two
examples are not such calls:

"A functional notation type conversion (5.2.3) can be used to create
new objects of its type. [Note: The syntax looks like an explicit call
of the constructor] [Example:

complex zz = complex(1,2.3);
cprint( complex(7.8,1.2) );

---end example] An object created in this way is unnamed. [Note: 12.2
describes the lifetime of temporary objects.] [Note: explicit
constructor calls do not yield lvalues, see 3.10]"

As you can see, what they are talking about in that section is indeed
not explicit constructor calls but the final note indicates that there
is such a thing and the first quote does not contradict that in any
way.

Finally, if that final note is a defect then where is the report?
 
N

Noah Roberts

Alf said:
string() is an explicit constructor call: the result is not an lvalue.

Where would that be used though? 12.1.13 would seem to indicate most
uses I have seen of such syntax are not in fact explicit constructor
calls.
 
V

Victor Bazarov

Noah said:
[..]
As you can see, what they are talking about in that section is indeed
not explicit constructor calls but the final note indicates that there
is such a thing and the first quote does not contradict that in any
way.

If I understand you correctly, the notes are intended to refer to some
other place in the Standard, where genuine, and existing for some other
purpose, explicit constructor calls are defined. Right? If you indeed
know about that other place in the Standard, are you going to keep it
a secret or are you going to share with us? Or am I misunderstanding
you here? Or are you just interpreting this paragraph _as_if_ that other
place in the Standard existed? Do tell.
Finally, if that final note is a defect then where is the report?

Nobody cared to submit a report on this yet, I am guessing. The absence
of a report is not a positive proof of the absence of a defect. I have
posted a message to comp.std.c++ asking about those two notes, as soon
as some conclusion is reached in the discussion that can insue, I'll
report back (for those who don't read c.s.c++).

V
 
A

Alf P. Steinbach

* Noah Roberts:
Where would that be used though?

Assuming you're asking where would one use an explicit default
constructor call, e.g. like

foo( std::string() + "Akka bakka " + someCString + "bonka rakka!" );

12.1.13 would seem to indicate most
uses I have seen of such syntax are not in fact explicit constructor
calls.

12.1/13 is unfortunately inconsistent in what it implies, but
fortunately not in its literal interpretation.

Follow the link to 3.10, and it becomes clear that an "explicit
constructor call" in the 12.1/13 note refers to the "invocations of
constructors" part of the 3.10/2 note, where the full context is
"invocations of constructors or functions that return a class type".

Now of course an invocation of something doesn't return a class type,
but instead returns a class type object, and it's a bit unclear whether
it's really meaningful to say that a constructor call returns anything
(which is one possible way to parse the sentence), so this is a further
example that the standard isn't perfect, but is written under an
assumption that readers will apply common sense.
 
N

Noah Roberts

Victor said:
Noah Roberts wrote:

Alf already mentioned another place where the standard mentions calling
a constructor:

12.1.5

"A default constructor for class X is a constructor of class X that can
be called without an argument."

Another:

12.1.8

"Default constructors are called implicitly to create class objects of
static or automatic storage duration..."

Obviously the standard indicates that a constructor can be "called" so
the term is obviously correct.
Nobody cared to submit a report on this yet, I am guessing. The absence
of a report is not a positive proof of the absence of a defect. I have
posted a message to comp.std.c++ asking about those two notes, as soon
as some conclusion is reached in the discussion that can insue, I'll
report back (for those who don't read c.s.c++).

After doing a search of the archives for that group (why didn't you
think of that?) I have to place my bets on a definative answer never
occuring. There are several places where members talk about explicitly
calling a constructor but no actual example that is given forth would
be convincing. For instance, several people describe placement new as
an explicit constructor call. Others indicate the following code:

class T {};

int main()
{

T();
};

This is an example of an explicit constructor call of type
T....creating an object that is never used. Others talk about the same
example in terms of it NOT being a constructor "call" or "invocation".

Yet another member asserts that static_cast is an explicit invocation
of the constructor:

(quote)
What is the rationale behind having static_cast invoke constructors
even if marked "explicit"?
I thought "explicit" was intended to say that a constructor does not
make sense as a conversion. But static_cast (or C style cast) is a
conversion that will use such a constructor anyway.

What "explicit" means is that the constructor should not be used unless
it is explicitly invoked. static_cast IS an explicit invocation of the
constructor.
(endquote)

So "static_cast<X>(y_inst)" would be considered an explicit call of the
constructor (assuming this conversion is possible). Others disagree of
course...

I don't think you are going to be able to say one way or the other. In
the end we are left with what the standard says when refering to
constructors and it repeatedly uses the term "call". Therefor anyone
else using the term is correct in doing so until that is changed in the
standard. Exactly what should be considered a call and what is not is
certainly highly debated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top