llvm/llvm-project

Decomposition Declaration diagnostic for missing initializer is pretty unclear

已关闭

#90,107 创建于 2024年4月25日

 (9 条评论) (0 个反应) (0 位负责人)C++ (10,782 个派生)batch import
clang:diagnosticsgood first issuequality-of-implementation

仓库指标

星标
 (26,378 个星标)
PR 合并指标
 (平均合并 1天 2小时) (30 天内合并 1,000 个 PR)

描述

Given the following code:

#include <utility>

std::pair<int, double> MyFunc();

void foo() {
    auto [A, B] C = MyFunc();
}

Our diagnostic is just:

<source>:9:10: error: decomposition declaration '[A, B]' requires an initializer
    9 |     auto [A, B] C = MyFunc();
      |          ^
<source>:9:16: error: expected ';' at end of declaration
    9 |     auto [A, B] C = MyFunc();
      |                ^
      |                ;
2 errors generated.
Compiler returned: 1

https://godbolt.org/z/h9zKT5zGe

No compilers are particularly good at this diagnostic, but all the others at least highlight the C as the mistake, whereas Clang's error is pretty opaque/points at the opening bracket.

I'd prefer we move the 'arrow' to the position where the initializer is expected. Additionally, some improved diagnostic wording that highlights what went wrong better would be appreciated.

贡献者指南