Skip to content

[BUG] Braces around assignment's RHS prevents deduction #312

@JohelEGP

Description

@JohelEGP

Describe the bug
feff640 added braces around the RHS of assignment in emitted assignment operators. This prevents deduction when the invoked assignment operator is a template, as a braced-init-list has no type.

To Reproduce
Steps to reproduce the behavior:

  1. Sample code
t1: type = {
  operator=: (out this, x) = {}
}

t2: type = {
  m: t1;
  operator=: (out this, a) = {
    m = a;
  }
}

main: () = {
  x: t2 = 0;
  x = 0;
}
  1. Command lines including which C++ compiler you are using
~/root/bin/cppfront x.cpp2 
~/root/clang/bin/clang++ -std=c++20 -I $CPPFRONT_INCLUDE_DIR x.cpp
clang version 17.0.0
  1. Expected result - what you expected to happen
    What happened before feff640.
  2. Actual result/error
x.cpp2:8:7: error: no viable overloaded '='
    m = {a};
    ~ ^ ~~~
x.cpp2:14:5: note: in instantiation of function template specialization 't2::operator=<int>' requested here
  x = 0;
    ^
x.cpp2:2:12: note: candidate template ignored: couldn't infer template argument 'x:auto'
  auto t1::operator=(auto const& x) -> t1& {
           ^
x.cpp2:1:7: note: candidate function (the implicit copy assignment operator) not viable: cannot convert initializer list argument to 'const t1'
class t1 {
      ^
x.cpp2:1:7: note: candidate function (the implicit move assignment operator) not viable: cannot convert initializer list argument to 't1'
class t1 {
      ^
1 error generated.

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