Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Missing declaration in initializer of constexpr variable #814

Closed
JohelEGP opened this issue Nov 12, 2023 · 1 comment
Closed

[BUG] Missing declaration in initializer of constexpr variable #814

JohelEGP opened this issue Nov 12, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

Title: Missing declaration in initializer of constexpr variable.

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

f :== :() = {
  x := 0;
  if (x) {
    _ = 0;
  }
};
main: () = { }
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp

Expected result: x to be declared in the emitted lambda expression.

Actual result and error:

auto inline constexpr f = []() -> void{if ((std::move(x))) {static_cast<void>(0);}};
Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



//=== Cpp2 type definitions and function declarations ===========================

auto inline constexpr f = []() -> void{if ((std::move(x))) {static_cast<void>(0);}};
  

auto main() -> int;


//=== Cpp2 function definitions =================================================


auto main() -> int{}
Output:
build/main.cpp:12:55: error: use of undeclared identifier 'x'
   12 | auto inline constexpr f = []() -> void{if ((std::move(x))) {static_cast<void>(0);}};
      |                                                       ^
1 error generated.
@JohelEGP JohelEGP added the bug Something isn't working label Nov 12, 2023
@hsutter
Copy link
Owner

hsutter commented Nov 19, 2023

Thanks! Fixed.

zaucy pushed a commit to zaucy/cppfront that referenced this issue Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants