Skip to content

[BUG] Object alias lowers to copy-initialization #699

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 Sep 24, 2023 · 0 comments · Fixed by #924
Closed

[BUG] Object alias lowers to copy-initialization #699

JohelEGP opened this issue Sep 24, 2023 · 0 comments · Fixed by #924
Labels
bug Something isn't working

Comments

@JohelEGP
Copy link
Contributor

Title: Object alias lowers to copy-initialization.

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

#include <array>
arr: std::array<int, 1> == (0);
main: () = { }
Commands:
cppfront main.cpp2
clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -I . main.cpp

Expected result:

std::array<int,1> inline constexpr arr{0};

Actual result and error:

std::array<int,1> inline constexpr arr = (0);
Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



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

#include <array>
std::array<int,1> inline constexpr arr = (0);
auto main() -> int;


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


auto main() -> int{}
Output:
main.cpp2:2:36: error: no viable conversion from 'int' to 'const std::array<int, 1>'
    2 | std::array<int,1> inline constexpr arr = (0);
      |                                    ^     ~~~
/opt/compiler-explorer/clang-trunk-20230923/bin/../include/c++/v1/array:164:29: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const array<int, 1> &' for 1st argument
  164 | struct _LIBCPP_TEMPLATE_VIS array
      |                             ^~~~~
/opt/compiler-explorer/clang-trunk-20230923/bin/../include/c++/v1/array:164:29: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'array<int, 1> &&' for 1st argument
  164 | struct _LIBCPP_TEMPLATE_VIS array
      |                             ^~~~~
1 error generated.

See also:

@JohelEGP JohelEGP added the bug Something isn't working label Sep 24, 2023
JohelEGP referenced this issue Sep 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…_enum`

Simplifying `enum` and `flag_enum` needed:

- evolving the `==` compile-time alias design to be the way we we express compile-time `constexpr` functions and objects

- including to work around Cpp1's limitation on declaring `constexpr`/`inline`/`static` members of a type that have an incomplete type, including the same type being defined, by using the dance described in https://stackoverflow.com/questions/11928089/

- enabling emitting `operator<<` as a `friend` function
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.

1 participant