Skip to content

clang candidate constructor behaves differently when it's implicitly defined #129400

@GhostCore07

Description

@GhostCore07

A user provided assignment operator works for some reason, as does also doing the implicit conversion without the assignment operator, but when the assignment operator is implicitly defined and you also have the implicit conversion it seems to not get the user defined conversion sequence correct. Note that the return type of the conversion sequence is const. Not a big deal.

struct A
{
    //A& operator=(const A& o);    
};
struct X
{
	operator const A();
};
void f()
{
    X a{};
    A b{};
    b = a;

    const A& c = a;
    b = c;
}
:13:9: error: no viable conversion from 'X' to 'A' 13 | b = a; | ^ :1:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'X' to 'const A &' for 1st argument 1 | struct A | ^ :1:8: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'X' to 'A &&' for 1st argument 1 | struct A | ^ :7:2: note: candidate function 7 | operator const A(); | ^ :1:8: note: passing argument to parameter here 1 | struct A | ^

https://godbolt.org/z/zcn7oTfjc

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions