303
303

Reputation: 4732

Discrepancy concerning default constructibility

Clang and GCC don't seem to agree about what makes a type default constructible. Is GCC wrong here? Is the formal definition of the standard not clear about this?

#include <concepts>

class base {
protected:
    base() = default;
};

struct der : base {
    using base::base;
    der(int) {}
};

der d; // constexpr base::base() is protected within this context
static_assert(std::semiregular<der>); // fails on GCC

Live example


JHBonarius and alagner have provided the requested information, referring to already existing sources that cover the details pretty well. For now, I think it's best to direct this question more towards Clang's deviating behavior. I've initiated the bug-reporting process and will post any follow ups here.

Upvotes: 3

Views: 90

Answers (1)

alagner
alagner

Reputation: 4062

As we discussed in the comments, seems GCC implements the standard right (though it seems counterintuitive):

C++ standard, 10.3.3.2

Each using-declarator in a using-declaration introduces a set of declarations into the declarative region in which the using-declaration appears. The set of declarations introduced by the using-declarator is found by performing qualified name lookup (6.4.3, 13.2) for the name in the using-declarator, excluding functions that are hidden as described below. If the using-declarator does not name a constructor, the unqualified-id is declared in the declarative region in which the using-declaration appears as a synonym for each declaration introduced by the using-declarator. [ Note: Only the specified name is so declared; specifying an enumeration name in a using-declaration does not declare its enumerators in the using-declaration’s declarative region. — end note ] If the using-declarator names a constructor, it declares that the class inherits the set of constructor declarations introduced by the using-declarator from the nominated base class.

Note that factory method works as expected.

EDIT: and it's been already asked and answered ;)

Upvotes: 3

Related Questions