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

Clang incorrectly considers a class with an anonymous union member to not be const-default-constructible even if a union member has a default member initializer #95854

Closed
zygoloid opened this issue Jun 17, 2024 · 9 comments · Fixed by #96301
Labels
c++11 clang:frontend Language frontend issues, e.g. anything involving "Sema" good first issue https://github.com/llvm/llvm-project/contribute rejects-valid

Comments

@zygoloid
Copy link
Collaborator

Testcase:

struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;

This is valid, but Clang rejects:

<source>:7:9: error: default initialization of an object of const type 'const A' without a user-provided default constructor

(Clang accepts if m is removed.) See https://eel.is/c++draft/dcl.init#general-8.3 -- because n has an initializer, the entire anonymous union is treated as initialized.

@zygoloid zygoloid added c++11 clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid labels Jun 17, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 17, 2024

@llvm/issue-subscribers-clang-frontend

Author: Richard Smith (zygoloid)

Testcase: ```c++ struct A { union { int n = 0; int m; }; }; const A a; ``` This is valid, but Clang rejects: ```console <source>:7:9: error: default initialization of an object of const type 'const A' without a user-provided default constructor ``` (Clang accepts if `m` is removed.) See https://eel.is/c++draft/dcl.init#general-8.3 -- because `n` has an initializer, the entire anonymous union is treated as initialized.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 17, 2024

@llvm/issue-subscribers-c-11

Author: Richard Smith (zygoloid)

Testcase: ```c++ struct A { union { int n = 0; int m; }; }; const A a; ``` This is valid, but Clang rejects: ```console <source>:7:9: error: default initialization of an object of const type 'const A' without a user-provided default constructor ``` (Clang accepts if `m` is removed.) See https://eel.is/c++draft/dcl.init#general-8.3 -- because `n` has an initializer, the entire anonymous union is treated as initialized.

@efriedma-quic
Copy link
Collaborator

I think CXXRecordDecl::allowConstDefaultInit() needs to special-case unions to handle the rule (specifically, it needs to check for HasInClassInitializer).

@efriedma-quic efriedma-quic added the good first issue https://github.com/llvm/llvm-project/contribute label Jun 18, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 18, 2024

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor has already been assigned to this issue. If you believe that no one is actually working on it despite an assignment, ping the person. After one week without a response, the assignee may be changed.
  2. In the comments of this issue, request for it to be assigned to you, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 18, 2024

@llvm/issue-subscribers-good-first-issue

Author: Richard Smith (zygoloid)

Testcase: ```c++ struct A { union { int n = 0; int m; }; }; const A a; ``` This is valid, but Clang rejects: ```console <source>:7:9: error: default initialization of an object of const type 'const A' without a user-provided default constructor ``` (Clang accepts if `m` is removed.) See https://eel.is/c++draft/dcl.init#general-8.3 -- because `n` has an initializer, the entire anonymous union is treated as initialized.

@ofAlpaca
Copy link
Contributor

This is my first time contributing to this project. I would like to give it a try. Could you assign it to me?

Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Jun 21, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Jun 22, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.
  This is valid as per ``8.3`` in `Draft C++ Standard <https://eel.is/c++draft/dcl.init#general-8.3>`_.
  The ``allowConstDefaultInit`` member function in ``CXXRecordDecl`` needs
  special-case unions to handle the rule. (#GH95854).

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
@ofAlpaca
Copy link
Contributor

Hi @zygoloid and @efriedma-quic,
I'm new here, so I don't quite understand the purpose of the 'good first issue' label.
I've noticed @Rajveer100 has been resolving many issues labeled as such.
I thought these issues were meant to help newcomers like me become more familiar with the LLVM project.
However, it looks like any contributor can take over this issue and fix it on their own without notifying assignee.
If senior LLVM contributors can solve any issues they want, what's the point of labeling them as 'good first issue'?
Once @Rajveer100 fix it, you can close this issue any time.
I think beginner is not welcome here.

@AaronBallman
Copy link
Collaborator

Hi @zygoloid and @efriedma-quic, I'm new here, so I don't quite understand the purpose of the 'good first issue' label.

We put that label on issues when we think it's something that a new contributor might be able to tackle as a way to get introduced to the code base.

I've noticed @Rajveer100 has been resolving many issues labeled as such. I thought these issues were meant to help newcomers like me become more familiar with the LLVM project. However, it looks like any contributor can take over this issue and fix it on their own without notifying assignee. If senior LLVM contributors can solve any issues they want, what's the point of labeling them as 'good first issue'? Once @Rajveer100 fix it, you can close this issue any time. I think beginner is not welcome here.

Any contributor can tackle any issue they'd like; we don't typically use issue assignments because of how easy it is for the assignment to go stale and then nobody works on it (but we have started assigning people when they ask to be assigned, sort of as a soft trial to see how well it goes). FWIW, @Rajveer100 is also a relative newcomer to the community and they may not have noticed that this issue was already assigned to you.

@ofAlpaca
Copy link
Contributor

Hi @AaronBallman
Thank you for your explanation.
I agree with you about the problem of assignment getting stalled.
However, @Rajveer100's behavior is still very unfriendly.

Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 10, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.
  This is valid as per ``8.3`` in `Draft C++ Standard <https://eel.is/c++draft/dcl.init#general-8.3>`_.
  The ``allowConstDefaultInit`` member function in ``CXXRecordDecl`` needs
  special-case unions to handle the rule. (#GH95854).

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 10, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.
  This is valid as per ``8.3`` in `Draft C++ Standard <https://eel.is/c++draft/dcl.init#general-8.3>`_.
  The ``allowConstDefaultInit`` member function in ``CXXRecordDecl`` needs
  special-case unions to handle the rule. (#GH95854).

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 13, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 27, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 27, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Aug 27, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
@ofAlpaca ofAlpaca removed their assignment Sep 2, 2024
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Sep 25, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Oct 1, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Oct 1, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Oct 16, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Oct 19, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Rajveer100 added a commit to Rajveer100/llvm-project that referenced this issue Oct 19, 2024
…onstructible even if a union member has a default member initializer (llvm#95854)

Resolves llvm#95854

  Clang incorrectly considers a class with an anonymous union member to not be
  const-default-constructible even if a union member has a default member initializer.

```
struct A {
  union {
    int n = 0;
    int m;
  };
};
const A a;
```

-- As per https://eel.is/c++draft/dcl.init#general-8.3
cor3ntin pushed a commit that referenced this issue Oct 22, 2024
…onstructible even if a union member has a default member initializer (#95854) (#96301)

Resolves #95854

-- As per https://eel.is/c++draft/dcl.init#general-8.3
EricWF pushed a commit to efcs/llvm-project that referenced this issue Oct 22, 2024
…onstructible even if a union member has a default member initializer (llvm#95854) (llvm#96301)

Resolves llvm#95854

-- As per https://eel.is/c++draft/dcl.init#general-8.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++11 clang:frontend Language frontend issues, e.g. anything involving "Sema" good first issue https://github.com/llvm/llvm-project/contribute rejects-valid
Projects
None yet
5 participants