Skip to content

CWG2871 [class.default.ctor] p1 should cover the constructor template  #510

Description

@xmh0511

Full name of submitter (unless configured in github; will be published with the issue): Jim X

[class.default.ctor] p1 says:

If there is no user-declared constructor for class X, a non-explicit constructor having no parameters is implicitly declared as defaulted ([dcl.fct.def]).

Consider this example:

struct X{
  template<class U> X(U){} // #2
};
int main(){
   X x;  // #1
}

#1 is ill-formed since no matching function for call to 'X::X()'. [class.default.ctor] p1 should cover this example, however, #2 is a user-declared constructor template, and the implicitly instantiated declaration is not user-declared anyway.

Suggested Resolution

If there is no user-declared constructor or constructor template for class X, a non-explicit constructor having no parameters is implicitly declared as defaulted ([dcl.fct.def]).

Activity

  1. changed the title [-][class.default.ctor] p1 should cover the constructor template [/-] [+]CWG2871 [class.default.ctor] p1 should cover the constructor template [/+] on Mar 17, 2024
  2. jensmaurer commented on Mar 17, 2024

    @jensmaurer
    Member
  3. lprv commented on Apr 6, 2024

    @lprv

    There are plenty of other uses of the undecorated term 'constructor' in the standard that are clearly meant to include templates: [basic.scope.scope]/4, [dcl.init.aggr]/1.1, [namespace.udecl]/2 and /13, [class.mem.general]/22, various subclauses of [over.match.funcs], etc. Why is it a problem in this particular case?

  4. frederick-vs-ja commented on Apr 8, 2024

    @frederick-vs-ja

    There are plenty of other uses of the undecorated term 'constructor' in the standard that are clearly meant to include templates: [basic.scope.scope]/4, [dcl.init.aggr]/1.1, [namespace.udecl]/2 and /13, [class.mem.general]/22, various subclauses of [over.match.funcs], etc. Why is it a problem in this particular case?

    Most are about inheriting constructors. I think there should be a concentrated issue on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions