Skip to content

[clang] "incomplete type 'const A' is not a literal type" for a static constexpr data member #162027

@mmatrosov

Description

@mmatrosov

Not sure if this is a bug or not, bug gcc compiles this code just fine:

template<typename Base>
struct Mixin {
  static constexpr Base base{};
};

struct A {
    Mixin<A> m;
};

while clang argues:

<source>:3:25: error: constexpr variable cannot have non-literal type 'const A'
    3 |   static constexpr Base base{};
      |                         ^
<source>:7:14: note: in instantiation of template class 'Mixin<A>' requested here
    7 |     Mixin<A> m;
      |              ^
<source>:3:25: note: incomplete type 'const A' is not a literal type
    3 |   static constexpr Base base{};
      |                         ^
<source>:6:8: note: definition of 'A' is not complete until the closing '}'
    6 | struct A {
      |        ^

https://godbolt.org/z/YbvW4Gq3n

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationdiverges-from:gccDoes the clang frontend diverge from gcc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions