Skip to content

Initializing a _Complex variable with an initializer list with too many items highlights the wrong item #61518

@tbaederr

Description

@tbaederr

See:

constexpr _Complex double d = {1.0, 2.0, 3.0, 45};
constexpr  double e[2]      = {1.0, 2.0, 3.0, 45};

Godbolt: https://godbolt.org/z/P7vqM4dq9

Output:

<source>:3:37: error: excess elements in scalar initializer
constexpr _Complex double d = {1.0, 2.0, 3.0, 45};
                                    ^~~
<source>:4:42: error: excess elements in array initializer
constexpr  double e[2]      = {1.0, 2.0, 3.0, 45};
                                         ^~~

Clang highlights the second entry for the _Complex variable, but it should highlight the third I think.

I have other issues with the diagnostics here, but since this is about _Complex and that is a fringe feature anyway, I don't care much about those and fixing the off-by-one error should be enough.

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partygood first issuehttps://github.com/llvm/llvm-project/contribute

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions