Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dcl.init.general] default-initialization vs extern declaration #4799

Open
xmh0511 opened this issue Aug 9, 2021 · 3 comments
Open

[dcl.init.general] default-initialization vs extern declaration #4799

xmh0511 opened this issue Aug 9, 2021 · 3 comments
Labels
cwg Issue must be reviewed by CWG.

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Aug 9, 2021

struct A{
  A(){}
};
extern A a; // #1

For the declaration at #1, should we say since there is no initializer specified for the object, hence default-initialization is applied?

Specifically, Is there any normative rule in the standard that specifies which declaration the initialization will be applied to?
Except for a note [dcl.init.general.note-10], it seems it's unclear whether the initialization is performed(on a declaration).

Could we change [dcl.init.general] p20 to

A simple-declaration that is definition specifies the initialization of a variable, whether from an explicit initializer or by default-initialization, is called the initializing declaration of that variable.

The modification does not impact member-declarations or parameter declarations, and it can clarify the above example.

@jensmaurer
Copy link
Member

The note that follows shows a situation where the initializing declaration is not a definition.

A declaration that specifies the initialization of a variable, whether from an explicit initializer or by default-
initialization, is called the initializing declaration of that variable.
[Note 10 : In most cases this is the defining declaration (6.2) of the variable, but the initializing declaration of a non-inline static data member (11.4.9.3) can be the declaration within the class definition and not the definition (if any) outside it. — end note]

Maybe we can say that a non-defining declaration can only be an initializing declaration if it has an (explicit) initializer.

@jensmaurer jensmaurer added the decision-required A decision of the editorial group (or the Project Editor) is required. label Aug 9, 2021
@xmh0511
Copy link
Contributor Author

xmh0511 commented Aug 10, 2021

If the original [dcl.init.general] p20 intends to cover all declarations of various variables, such as, the parameter declaration that appears in a function-definition, the proposal is not sufficient. In my mind, a parameter-declaration can never be an initializing declaration but in this case, it is a definition. As well as exception-declaration.

@jensmaurer
Copy link
Member

The current definition of "initializing declaration" seems lacking; maybe we should restrict the definition to non-function parameters or so.

@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. and removed decision-required A decision of the editorial group (or the Project Editor) is required. labels Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG.
Projects
None yet
Development

No branches or pull requests

2 participants