Skip to content

[temp.deduct.call] Deduction rules for array sizes are inconsistent with character array initialization #727

Open
@Eisenwave

Description

@Eisenwave

Reference (section label): [temp.deduct.call]

Issue description

Consider the following example:

struct T {
  template<int N>
  T(const char(&)[N]) {}
};

struct S {
  S(const char(&)[5]) {}
};

T t({"awoo"}); // error: initializer-string for char array is too long
S s({"awoo"}); // OK

There is a surprising and likely unintentional inconsistency here. Implementations diverge on whether the initialization of t is valid.

While [dcl.init.string] generally allows initialization of character arrays with a string-literal that is surrounded by braces, [temp.deduct.call] paragraph 1 states that N is deduced to the length of the initializer list, which is 1, resulting in a failed attempt at initializing const char(&)[1] with "awoo".

Suggested resolution

W.I.P.

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