Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Follow-up: What exactly is a variable in C++14/C++17?

As the title suggests, this question has been asked before. However, the answers pertained to C++03/0x(11). C++11 (N3337) says this about variables:

[basic]/6:

A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object.

This may imply that variables are essentially named objects/references.

However, in C++14/C++17, that last sentence was changed to

The variable’s name, if any, denotes the reference or object.

which implies that a variable does not necessarily have a name.

A different interpretation of the first sentence may suggest that a variable is a name, since a name denoting an object/reference is also introduced by a declaration of such entities. But the second sentence contradicts that notion with the phrase "variable's name". So, is variable now just a hypernym for object and reference, whether named or not?

like image 333
TSmith Avatar asked Jun 29 '18 18:06

TSmith


1 Answers

This change was a result of CWG 1769, addressing the status of exception objects bound to unnamed catch handler parameters:

catch (std::exception&) // <==
{ 
}

That is now a variable. This simplifies the conceptual model around exception objects.

The first sentence, which remained unchanged, is still the complete definition of the term variable.

like image 66
Barry Avatar answered Oct 16 '22 16:10

Barry