What is a non-inline static data member?

64 views
Skip to first unread message

Belloc

unread,
Dec 8, 2016, 3:13:13 PM12/8/16
to ISO C++ Standard - Discussion
The Standard makes a few references to this term but apparently it doesn't define it.

I'm particularly interested in the three references highlighted below:


(2.3) — it declares a non-inline static data member in a class definition (9.2, 9.2.3),


The declaration of a non-inline static data member in its class definition is not a definition and may be of
an incomplete type other than cv void. The definition for a static data member that is not defined inline
in the class definition shall appear in a namespace scope enclosing the member’s class definition. In the
definition at namespace scope, the name of the static data member shall be qualified by its class name using
the :: operator. The initializer expression in the definition of a static data member is in the scope of its
class (3.3.7). [ Example:
 
class process {
   
static process* run_chain;
   
static process* running;
};
process
* process::running = get_main();
process
* process::run_chain = running;

The static data member run_chain of class process is defined in global scope; the notation process::run_chain
specifies that the member run_chain is a member of class process and in the scope of class process.
In the static data member definition, the initializer expression refers to the static data member running of
class process. —end example ]

As far as I can understand run_chain and running in the example are inline static data members, which
are defined in global scope.


If a non-volatile non-inline const static data member is of integral or enumeration type, its declaration
in the class definition can specify a brace-or-equal-initializer in which every initializer-clause that is an
assignment-expression is a constant expression (5.20). The member shall still be defined in a namespace scope
if it is odr-used (3.2) in the program and the namespace scope definition shall not contain an initializer. An
inline static data member may be defined in the class definition and may specify a brace-or-equal-initializer.
If the member is declared with the constexpr specifier, it may be redeclared in namespace scope with no
initializer (this usage is deprecated; see D.1). Declarations of other static data members shall not specify a
brace-or-equal-initializer.

I believe this paragraph is talking about the data member declaration below

struct A{
   
static const int i = 11;
};

By the same token, the data member i above is an inline const static data member. Note the word inline above.
As far as I can understand, it seems to contradict the non-inline usage at the beginning of the paragraph.

Richard Smith

unread,
Dec 8, 2016, 6:45:39 PM12/8/16
to std-dis...@isocpp.org
On 8 Dec 2016 12:13 pm, "Belloc" <jabe...@gmail.com> wrote:
The Standard makes a few references to this term but apparently it doesn't define it.

Inline variable is defined here: http://eel.is/c++draft/dcl.inline#3
Note that a static data member is a kind of variable.

See also http://eel.is/c++draft/dcl.constexpr#1, which classifies some variables as inline implicitly.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.

Belloc

unread,
Dec 9, 2016, 5:57:18 AM12/9/16
to ISO C++ Standard - Discussion


On Thursday, December 8, 2016 at 9:45:39 PM UTC-2, Richard Smith wrote:

Inline variable is defined here: http://eel.is/c++draft/dcl.inline#3
Note that a static data member is a kind of variable.

See also http://eel.is/c++draft/dcl.constexpr#1, which classifies some variables as inline implicitly.

Thanks for the information. I have just found the paper introducing this new feature. 
Reply all
Reply to author
Forward
0 new messages