Skip to content

[BUG] Argument list parentheses kept in non-local initialization #597

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

Closed
JohelEGP opened this issue Aug 17, 2023 · 5 comments · Fixed by #599
Closed

[BUG] Argument list parentheses kept in non-local initialization #597

JohelEGP opened this issue Aug 17, 2023 · 5 comments · Fixed by #599
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

Title: Argument list parentheses kept in non-local initialization.

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

u: type == std::array<i32, 2>;
t: @struct type = {
  this: std::integral_constant<u, :u = (17, 29)>;
}
main: () = _ = :u = (17, 29);;
Commands:
cppfront main.cpp2
clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -fsanitize=undefined -Werror=unused-result -I . main.cpp

Expected result: No warnings; same as the u in main.

Actual result and error:

Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"


class t;
  

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

using u = std::array<cpp2::i32,2>;
class t: public std::integral_constant<u,u{(17, 29)}> {

};
auto main() -> int;


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


auto main() -> int { static_cast<void>(u{17, 29});  }
Output:
main.cpp2:2:45: warning: left operand of comma operator has no effect [-Wunused-value]
    2 | class t: public std::integral_constant<u,u{(17, 29)}> {
      |                                             ^~
1 warning generated.
@JohelEGP JohelEGP added the bug Something isn't working label Aug 17, 2023
@JohelEGP
Copy link
Contributor Author

This is just a duplicate of #503.

@jcanizales
Copy link

main: () = _ = :u = (17, 29);;

What is the meaning of this?

@JohelEGP
Copy link
Contributor Author

If you mean the extra semicolon, there's a few open bugs in the area: https://github.com/hsutter/cppfront/issues?q=is%3Aissue+is%3Aopen+unnamed+declaration+in%3Atitle+.
#479 is also related, see in particuar: https://github.com/hsutter/cppfront/pull/479/files#diff-43ba71198da8225f205041c699dba495883d7d416c0b58916bf226aae97bafaeR4069-R4071.
I haven't reported this particular instance, yet. Maybe it'd be a duplicate of another one.

Otherwise,
we're discarding (_ =) an unnamed declaration of u initialized with (17, 29)
in main's expression-statement's body.

@JohelEGP
Copy link
Contributor Author

Opened #611 for that now.

@jcanizales
Copy link

Thanks for the explanation!

hsutter pushed a commit that referenced this issue Aug 31, 2023
* fix(parse): add missing condition for "inside initializer"

* test: use the test case from #597
zaucy pushed a commit to zaucy/cppfront that referenced this issue Dec 5, 2023
* fix(parse): add missing condition for "inside initializer"

* test: use the test case from hsutter#597
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

Successfully merging a pull request may close this issue.

2 participants