Skip to content

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

@zygoloid

Description

@zygoloid

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++11clang:frontendLanguage frontend issues, e.g. anything involving "Sema"good first issuehttps://github.com/llvm/llvm-project/contributerejects-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions