Skip to content

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

Closed

Description

@JohelEGP

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions