hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler
Other
5.45k stars 239 forks source link

[BUG] Wrong error message for variable left uninitialized #1288

Open JohelEGP opened 2 hours ago

JohelEGP commented 2 hours ago

Title: Wrong error message for variable left uninitialized.

Description:

This change might have to do with commit 797569a67ba70289d8705ab0d57ab6b4a277c345. There need to be regression tests for all of cppfront's diagnostics.

Minimal reproducer (https://cpp2.godbolt.org/z/MzqbWKzM9):

main: () = {
  x: int;
}

Commands: ```bash cppfront main.cpp2 clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -Werror=unused-variable -I . main.cpp ```

Expected result: A diagnostic about x never being initialized.

Actual result and error:

Output:

main.cpp2...
main.cpp2(2,3): error: local variable x is used before it was initialized
  ==> program violates initialization safety guarantee - see previous errors
JohelEGP commented 2 hours ago

Also, what happened to cppfront's unused variable diagnostic? I remember that being a thing, though I may be wrong. See https://cpp2.godbolt.org/z/6n63hzzo3, which is rejected by the Cpp1 compiler via -Werror,-Wunused-variable.