Skip to content

[clang][diagnostics] -Wunreachable-code prints incorrect source range if a constructor has a default value set to a builtin #93725

Closed
@alanzhao1

Description

@alanzhao1

Originally reported in #91879 (comment)

After #91879, unreachable calls to constructors with default parameters set to builtins would underline the builtin as the source range instead of the call to the constructor - e.g.

struct A {
  explicit A(int = __builtin_LINE());
};

int h(int a) {
  return 3;
  A();
}

used to produce the diagnostic

<source>:7:3: error: code will never be executed [-Werror,-Wunreachable-code]
    7 |   A();
      |   ^~~

but now produces the (incorrect) diagnostic

    2 |   explicit A(int = __builtin_LINE());
      |                    ^~~~~~~~~~~~~~~~

godbolt: https://godbolt.org/z/6TEdrx55d

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions