Skip to content
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

nameless struct leads to deleted operator== with no diagnostics #92497

Open
tiagomacarios opened this issue May 17, 2024 · 4 comments · May be fixed by #93380
Open

nameless struct leads to deleted operator== with no diagnostics #92497

tiagomacarios opened this issue May 17, 2024 · 4 comments · May be fixed by #93380
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@tiagomacarios
Copy link
Contributor

The following code:
https://godbolt.org/z/rM83Md9jT

struct S {
    struct {
        bool b;
    };

    bool operator==(const S&) const noexcept = default;
};

bool f(S const& a, S const& b) { return a == b; }

int main() {}

Fails at link time with:

<source>:9:(.text+0x19): undefined reference to `S::operator==(S const&) const'

gcc diagnostics are much better and earlier (compile time):

<source>:9:46: error: use of deleted function 'constexpr bool S::operator==(const S&) const'
    9 | bool f(S const& a, S const& b) { return a == b; }
      |                                              ^
<source>:6:10: note: 'constexpr bool S::operator==(const S&) const' is implicitly deleted because the default definition would be ill-formed:
    6 |     bool operator==(const S&) const noexcept = default;
      |          ^~~~~~~~
<source>:2:5: error: no match for 'operator==' (operand types are 'S::<unnamed struct>' and 'S::<unnamed struct>')
    2 |     struct {
      |     ^~~~~~

Could we add the same warning as gcc?

@MitalAshok
Copy link
Contributor

Definitely a bug. This related snippet:

struct S {
    struct {
        bool b;
    };

    bool operator==(const S&) const noexcept;
};

bool S::operator==(const S&) const noexcept = default;

bool f(S const& a, S const& b) { return a == b; }

is invalid but causes a crash https://godbolt.org/z/1Kj4s8axT

<source>:11:41: error: cannot compile this scalar expression yet
   11 | bool f(S const& a, S const& b) { return a == b; }
      |                                         ^~~~~~
Unexpected placeholder builtin type!
UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CodeGenTypes.cpp:542!

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels May 17, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 17, 2024

@llvm/issue-subscribers-clang-frontend

Author: Tiago (tiagomacarios)

The following code: https://godbolt.org/z/rM83Md9jT ``` struct S { struct { bool b; };
bool operator==(const S&amp;) const noexcept = default;

};

bool f(S const& a, S const& b) { return a == b; }

int main() {}


Fails at link time with:

<source>:9:(.text+0x19): undefined reference to `S::operator==(S const&) const'


gcc diagnostics are much better and earlier (compile time):

<source>:9:46: error: use of deleted function 'constexpr bool S::operator==(const S&) const'
9 | bool f(S const& a, S const& b) { return a == b; }
| ^
<source>:6:10: note: 'constexpr bool S::operator==(const S&) const' is implicitly deleted because the default definition would be ill-formed:
6 | bool operator==(const S&) const noexcept = default;
| ^~~~~~~~
<source>:2:5: error: no match for 'operator==' (operand types are 'S::<unnamed struct>' and 'S::<unnamed struct>')
2 | struct {
| ^~~~~~


Could we add the same warning as gcc?
</details>

@shafik
Copy link
Collaborator

shafik commented May 18, 2024

Worth noting edg/MSVC accept, the original example: https://godbolt.org/z/GMv36vYKr

CC @Endilll

@zygoloid
Copy link
Collaborator

Ideally it seems like we should accept this, and compare the anonymous struct member elementwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
6 participants