<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Clang crashes on implicit size_t operator with defaulted comparison operator"
href="https://bugs.llvm.org/show_bug.cgi?id=50319">50319</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang crashes on implicit size_t operator with defaulted comparison operator
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>12.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>electrocartridge@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>### Source code
#include <iostream>
struct Struct {
int x;
bool operator<(const Struct&) const = default;
operator size_t() const {
return x;
}
};
int main() {
Struct s;
std::cout << s.x << std::endl;
}
### Clang output
<source>:6:10: warning: explicitly defaulted relational comparison operator is
implicitly deleted [-Wdefaulted-function-deleted]
bool operator<(const Struct&) const = default;
^
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-12.0.0/bin/clang++ -g
-o /app/output.s -mllvm --x86-asm-syntax=intel -S
--gcc-toolchain=/opt/compiler-explorer/gcc-10.3.0 -fcolor-diagnostics
-fno-crash-diagnostics -std=c++20 <source>
1. <source>:11:2: current parser token ';'
2. <source>:3:1: parsing struct/union/class body 'Struct'
#0 0x0000560187b12b2c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x3000b2c)
#1 0x0000560187b108d4 llvm::sys::RunSignalHandlers()
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x2ffe8d4)
#2 0x0000560187b10b55 llvm::sys::CleanupOnSignal(unsigned long)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x2ffeb55)
#3 0x0000560187a794e8 CrashRecoverySignalHandler(int)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x2f674e8)
#4 0x00007f80bbf043c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
#5 0x00005601899f1446 (anonymous
namespace)::DefaultedComparisonAnalyzer::visitBinaryOperator(clang::OverloadedOperatorKind,
llvm::ArrayRef<clang::Expr*>, (anonymous
namespace)::DefaultedComparisonSubobject, clang::OverloadCandidateSet*)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4edf446)
#6 0x0000560189a024a6 (anonymous
namespace)::DefaultedComparisonAnalyzer::visit()
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4ef04a6)
#7 0x0000560189a05950
clang::Sema::CheckExplicitlyDefaultedComparison(clang::Scope*,
clang::FunctionDecl*, clang::Sema::DefaultedComparisonKind)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4ef3950)
#8 0x0000560189a1a7f5
clang::Sema::CheckExplicitlyDefaultedFunction(clang::Scope*,
clang::FunctionDecl*)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4f087f5)
#9 0x0000560189a23f64 clang::Sema::CheckCompletedCXXClass(clang::Scope*,
clang::CXXRecordDecl*)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4f11f64)
#10 0x0000560189a25fef
clang::Sema::ActOnFinishCXXMemberSpecification(clang::Scope*,
clang::SourceLocation, clang::Decl*, clang::SourceLocation,
clang::SourceLocation, clang::ParsedAttributesView const&)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4f13fef)
#11 0x000056018976a038
clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation,
clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&, unsigned int,
clang::Decl*) (/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4c58038)
#12 0x000056018976c1ab
clang::Parser::ParseClassSpecifier(clang::tok::TokenKind,
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo
const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext,
clang::Parser::ParsedAttributesWithRange&)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4c5a1ab)
#13 0x000056018974d001
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier,
clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4c3b001)
#14 0x0000560189724edf
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4c12edf)
#15 0x00005601897257a1
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.241)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4c137a1)
#16 0x000056018972b729
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4c19729)
#17 0x000056018972cca9
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4c1aca9)
#18 0x000056018971ff09 clang::ParseAST(clang::Sema&, bool, bool)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x4c0df09)
#19 0x000056018895fe42 clang::CodeGenAction::ExecuteAction()
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x3e4de42)
#20 0x0000560188367191 clang::FrontendAction::Execute()
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x3855191)
#21 0x000056018830d593
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x37fb593)
#22 0x000056018842f363
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x391d363)
#23 0x0000560185ae209c cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/opt/compiler-explorer/clang-12.0.0/bin/clang+++0xfd009c)
#24 0x0000560185ade61d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0xfcc61d)
#25 0x00005601881cf215 void llvm::function_ref<void
()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__cxx11::basic_string<char, std::char_traits<char>,</span >
std::allocator<char> >*, bool*) const::'lambda'()>(long)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x36bd215)
#26 0x0000560187a795c3
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x2f675c3)
#27 0x00005601881cfd68
clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__cxx11::basic_string<char, std::char_traits<char>,</span >
std::allocator<char> >*, bool*) const (.part.174)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x36bdd68)
#28 0x00005601881a88ba
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&,
clang::driver::Command const*&) const
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x36968ba)
#29 0x00005601881a940f
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x369740f)
#30 0x00005601881b2215
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&)
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0x36a0215)
#31 0x0000560185a0ab4c main
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0xef8b4c)
#32 0x00007f80bb9b50b3 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#33 0x0000560185ade19a _start
(/opt/compiler-explorer/clang-12.0.0/bin/clang+++0xfcc19a)
clang-12: error: clang frontend command failed with exit code 139 (use -v to
see invocation)
Compiler returned: 139
### Expected behavior
I'd expect clang to note that this case is ambiguous, because operator size_t
is not explicit, hence we cannot determine how to compare Struct with size_t:
bool fn() {
Struct l{ .x = 1 };
size_t r = 2;
return l < r;
}
or smth like that
### Hardware / OSes
macOS 10.15.7
Default hardware on Godbolt: <a href="https://godbolt.org/z/P6Kn68T68">https://godbolt.org/z/P6Kn68T68</a>
I suppose this will be reproduced on Linux also</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>