Skip to content

[clang] Class gets an implicit default constructor when it has a user-provided constructor #167136

@carljohnsonnewhampshire-hue

Description

The following code doesn't compile due to failed static assertion in Clang, but does compile in MSVC:

struct A
{
  template <int=0>
  constexpr A() noexcept {}
};

struct B : A
{
  using A::A;
  explicit constexpr B(int) noexcept {}
};

struct C : B
{
  using B::B;

  template <int=0>
  constexpr C() noexcept : a(1) {}

  int a = 0;
};

static_assert(C().a == 1);

This is not standard compliant, that code should compile. According to the standard A's constructor is not a default constructor per-se, as in "special member function" kind of default constructor -- it is a template for a constructor that takes no arguments, thus A does not have an implicit default constructor, so nor should B which inherits from it and its constructor using the using declaration. But clang seems to think here that because A is default-constructible (which it is, despite not having "real" default constructor), that B should get an implicit default constructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions