r319513 - [c++2a] P0515R3: Support for overloaded operator<=>.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 30 18:13:10 PST 2017
Author: rsmith
Date: Thu Nov 30 18:13:10 2017
New Revision: 319513
URL: http://llvm.org/viewvc/llvm-project?rev=319513&view=rev
Log:
[c++2a] P0515R3: Support for overloaded operator<=>.
No CodeGen support for MSABI yet, we don't know how to mangle this there.
Added:
cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp
cfe/trunk/test/SemaCXX/cxx2a-three-way-comparison.cpp
Modified:
cfe/trunk/include/clang/Basic/OperatorKinds.def
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/Lexer/cxx2a-spaceship.cpp
Modified: cfe/trunk/include/clang/Basic/OperatorKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OperatorKinds.def?rev=319513&r1=319512&r2=319513&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/OperatorKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OperatorKinds.def Thu Nov 30 18:13:10 2017
@@ -89,6 +89,7 @@ OVERLOADED_OPERATOR(EqualEqual
OVERLOADED_OPERATOR(ExclaimEqual , "!=" , exclaimequal , false, true , false)
OVERLOADED_OPERATOR(LessEqual , "<=" , lessequal , false, true , false)
OVERLOADED_OPERATOR(GreaterEqual , ">=" , greaterequal , false, true , false)
+OVERLOADED_OPERATOR(Spaceship , "<=>" , spaceship , false, true , false)
OVERLOADED_OPERATOR(AmpAmp , "&&" , ampamp , false, true , false)
OVERLOADED_OPERATOR(PipePipe , "||" , pipepipe , false, true , false)
OVERLOADED_OPERATOR(PlusPlus , "++" , plusplus , true , true , false)
Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=319513&r1=319512&r2=319513&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Thu Nov 30 18:13:10 2017
@@ -2195,6 +2195,9 @@ CXXNameMangler::mangleOperatorName(Overl
// Proposal on cxx-abi-dev, 2015-10-21.
// ::= aw # co_await
case OO_Coawait: Out << "aw"; break;
+ // Proposed in cxx-abi github issue 43.
+ // ::= ss # <=>
+ case OO_Spaceship: Out << "ss"; break;
case OO_None:
case NUM_OVERLOADED_OPERATORS:
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=319513&r1=319512&r2=319513&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Nov 30 18:13:10 2017
@@ -1192,6 +1192,15 @@ void MicrosoftCXXNameMangler::mangleOper
// <operator-name> ::= ?__L # co_await
case OO_Coawait: Out << "?__L"; break;
+ case OO_Spaceship: {
+ // FIXME: Once MS picks a mangling, use it.
+ DiagnosticsEngine &Diags = Context.getDiags();
+ unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
+ "cannot mangle this three-way comparison operator yet");
+ Diags.Report(Loc, DiagID);
+ break;
+ }
+
case OO_Conditional: {
DiagnosticsEngine &Diags = Context.getDiags();
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=319513&r1=319512&r2=319513&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Thu Nov 30 18:13:10 2017
@@ -1384,6 +1384,10 @@ static Stmt::StmtClass DecodeOperatorCal
case OO_GreaterEqual:
BinaryOp = BO_GE;
return Stmt::BinaryOperatorClass;
+
+ case OO_Spaceship:
+ // FIXME: Update this once we support <=> expressions.
+ llvm_unreachable("<=> expressions not supported yet");
case OO_AmpAmp:
BinaryOp = BO_LAnd;
Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=319513&r1=319512&r2=319513&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Thu Nov 30 18:13:10 2017
@@ -2184,7 +2184,7 @@ bool Parser::ParseUnqualifiedIdTemplateI
/// ! = < > += -= *= /= %=
/// ^= &= |= << >> >>= <<= == !=
/// <= >= && || ++ -- , ->* ->
-/// () []
+/// () [] <=>
///
/// conversion-function-id: [C++ 12.3.2]
/// operator conversion-type-id
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=319513&r1=319512&r2=319513&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Nov 30 18:13:10 2017
@@ -9902,6 +9902,7 @@ static bool ActOnOMPReductionKindClause(
case OO_GreaterGreaterEqual:
case OO_EqualEqual:
case OO_ExclaimEqual:
+ case OO_Spaceship:
case OO_PlusPlus:
case OO_MinusMinus:
case OO_Comma:
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=319513&r1=319512&r2=319513&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Nov 30 18:13:10 2017
@@ -8692,6 +8692,9 @@ void Sema::AddBuiltinOperatorCandidates(
OpBuilder.addGenericBinaryArithmeticOverloads();
break;
+ case OO_Spaceship:
+ llvm_unreachable("<=> expressions not supported yet");
+
case OO_Percent:
case OO_Caret:
case OO_Pipe:
Added: cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp?rev=319513&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/cxx2a-three-way-comparison.cpp Thu Nov 30 18:13:10 2017
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %itanium_abi_triple | FileCheck %s --check-prefix=ITANIUM
+// RUN: not %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %ms_abi_triple 2>&1 | FileCheck %s --check-prefix=MSABI
+// MSABI: cannot mangle this three-way comparison operator yet
+
+struct A {
+ void operator<=>(int);
+};
+
+// ITANIUM: define {{.*}}@_ZN1AssEi(
+void A::operator<=>(int) {}
+
+// ITANIUM: define {{.*}}@_Zssi1A(
+void operator<=>(int, A) {}
Modified: cfe/trunk/test/Lexer/cxx2a-spaceship.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/cxx2a-spaceship.cpp?rev=319513&r1=319512&r2=319513&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/cxx2a-spaceship.cpp (original)
+++ cfe/trunk/test/Lexer/cxx2a-spaceship.cpp Thu Nov 30 18:13:10 2017
@@ -10,7 +10,7 @@ namespace N {
struct A {};
void operator<=(A, A);
#if __cplusplus > 201703L
-void operator<=>(A, A); // expected-error {{}}
+void operator<=>(A, A);
#ifdef COMPAT
// expected-warning at -2 {{'<=>' operator is incompatible with C++ standards before C++2a}}
#endif
@@ -21,7 +21,7 @@ X<operator<=>
#if __cplusplus <= 201703L
// expected-warning at -2 {{'<=>' is a single token in C++2a; add a space to avoid a change in behavior}}
#else
- > // expected-error at -4 {{}}
+ >
#endif
#ifdef COMPAT
// expected-warning at -7 {{'<=>' operator is incompatible with C++ standards before C++2a}}
Added: cfe/trunk/test/SemaCXX/cxx2a-three-way-comparison.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx2a-three-way-comparison.cpp?rev=319513&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx2a-three-way-comparison.cpp (added)
+++ cfe/trunk/test/SemaCXX/cxx2a-three-way-comparison.cpp Thu Nov 30 18:13:10 2017
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+struct A {};
+constexpr int operator<=>(A a, A b) { return 42; }
+static_assert(operator<=>(A(), A()) == 42);
+
+int operator<=>(); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}}
+int operator<=>(A); // expected-error {{overloaded 'operator<=>' must be a binary operator}}
+int operator<=>(int, int); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}}
+int operator<=>(A, A, A); // expected-error {{overloaded 'operator<=>' must be a binary operator}}
+int operator<=>(A, A, ...); // expected-error {{overloaded 'operator<=>' cannot be variadic}}
+int operator<=>(int, A = {}); // expected-error {{parameter of overloaded 'operator<=>' cannot have a default argument}}
+
+struct B {
+ int &operator<=>(int);
+ friend int operator<=>(A, B);
+
+ friend int operator<=>(int, int); // expected-error {{overloaded 'operator<=>' must have at least one parameter of class or enumeration type}}
+ void operator<=>(); // expected-error {{overloaded 'operator<=>' must be a binary operator}};
+ void operator<=>(A, ...); // expected-error {{overloaded 'operator<=>' cannot be variadic}}
+ void operator<=>(A, A); // expected-error {{overloaded 'operator<=>' must be a binary operator}};
+};
+
+int &r = B().operator<=>(0);
More information about the cfe-commits
mailing list