[PATCH] D45476: [C++2a] Implement operator<=> CodeGen and ExprConstant

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 3 23:02:39 PDT 2018


rjmccall added inline comments.


================
Comment at: lib/Sema/SemaDeclCXX.cpp:8931
+                          /*ConstArg*/ true, false, false, false, false);
+  auto *CopyCtor = cast_or_null<CXXConstructorDecl>(SMI.getMethod());
+
----------------
Sorry, I didn't realize you'd go off and write this code manually.

The way we generally handle this sort of thing is just to synthesize an expression in Sema that performs the copy-construction.  That way, the stdlib can be as crazy as it wants — default arguments on the copy-constructor or whatever else — and it just works.  The pattern to follow here is the code in Sema::BuildExceptionDeclaration, except that in your case you can completely dispense with faking up an OpaqueValueExpr and instead just build a DeclRefExpr to the actual variable.  (You could even use ActOnIdExpression for this, although just synthesizing the DRE shouldn't be too hard.)  Then the ComparisonCategoryInfo can just store expressions for each of the three (four?) variables, and in IRGen you just evaluate the appropriate one into the destination.


https://reviews.llvm.org/D45476





More information about the cfe-commits mailing list