Skip to content

Renaming macro definition symbol incorrect when macro definition appears after #include directive #14130

@coerq

Description

@coerq

Environment

  • OS and Version: Windows_NT x64 10.0.26200
  • VS Code Version: 1.107.1
  • C/C++ Extension Version: 1.29.3

Bug Summary and Steps to Reproduce

Bug Summary:

When renaming macro definition symbols (by pressing F2), I noticed that the behavior of renaming is inconsistent, depending on the relative position of the macro definition and the #include directive:

  1. When the macro definition appears after the #include directive:
    The usage of the macro is renamed, but the macro definition itself is not renamed.

  2. When the macro definition appears before the #include directive:
    Both the macro definition and its usage are renamed correctly.

Steps to reproduce:

  1. Create a C/C++ file, e.g., test.c.
  2. Define a macro after the #include directive, for example:
#include <stdio.h>

#define TEST 1

int main() {
    printf("%d\n", TEST);
}
  1. Try renaming TEST using F2.

  2. Observe the result: The macro usage (the printf line) is renamed, but the macro definition (the #define line) remains unchanged.

  3. Swap the order of the macro definition and the #include directive, repeat step 3, and observe whether both are renamed.

Expected behavior:

Regardless of the relative position of the macro definition and the #include directive, renaming a macro should rename both the macro definition and all its usages.

Configuration and Logs

Only the compiler path has been added, and other configurations remain at their default values:
{
    "C_Cpp.default.compilerPath": "c:\\ProgramFiles\\ArmGun\\bin\\arm-none-eabi-gcc.exe"
}

Other Extensions

No response

Additional context

No response

Metadata

Metadata

Assignees

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions