Author: Pavel Samolysov Date: 2024-07-28T13:44:57+03:00 New Revision: 81595e9178eedc18dfcace9ac412f20697497f9f
URL: https://github.com/llvm/llvm-project/commit/81595e9178eedc18dfcace9ac412f20697497f9f DIFF: https://github.com/llvm/llvm-project/commit/81595e9178eedc18dfcace9ac412f20697497f9f.diff LOG: [Clang][Sema] Add a test for move ctor calling for a base class. NFC (#97164) When clang compiles the following expression: ```c++ return A{B{"Move Ctor"}}; ``` (where `B` is a base class for `A`), it adds a call to the move constructor of `B`. When the code is changed to... ```c++ return A{{"No Move Ctor"}}; ``` ... a move constructor is invoked neither for `A` nor for `B`. The lit test demonstrates the difference in the generated AST. Added: clang/test/AST/explicit-base-class-move-cntr.cpp Modified: Removed: ################################################################################ diff --git a/clang/test/AST/explicit-base-class-move-cntr.cpp b/clang/test/AST/explicit-base-class-move-cntr.cpp new file mode 100644 index 0000000000000..808af2fc94336 --- /dev/null +++ b/clang/test/AST/explicit-base-class-move-cntr.cpp @@ -0,0 +1,171 @@ +// RUN: %clang_cc1 -ast-dump=json %s | FileCheck -strict-whitespace %s + +struct ExplicitBase { + explicit ExplicitBase(const char *) { } + ExplicitBase(const ExplicitBase &) {} + ExplicitBase(ExplicitBase &&) {} + ExplicitBase &operator=(const ExplicitBase &) { return *this; } + ExplicitBase &operator=(ExplicitBase &&) { return *this; } + ~ExplicitBase() { } +}; + +struct Derived1 : ExplicitBase {}; + +Derived1 makeDerived1() { +// CHECK: "kind": "FunctionDecl", +// CHECK: "name": "makeDerived1", + +// CHECK: "kind": "CompoundStmt", + +// CHECK: "kind": "ReturnStmt", +// CHECK: "kind": "ExprWithCleanups", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "Derived1" +// CHECK-NEXT: }, + +// CHECK: "kind": "CXXFunctionalCastExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "Derived1" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", +// CHECK-NEXT: "castKind": "NoOp", + +// CHECK: "kind": "CXXBindTemporaryExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "Derived1" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", + +// CHECK: "kind": "InitListExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "Derived1" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", + +// CHECK: "kind": "CXXConstructExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "ExplicitBase" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", +// CHECK-NEXT: "ctorType": { +// CHECK-NEXT: "qualType": "void (ExplicitBase &&)" +// CHECK-NEXT: }, +// CHECK-NEXT: "hadMultipleCandidates": true, +// CHECK-NEXT: "constructionKind": "non-virtual base", + +// CHECK: "kind": "MaterializeTemporaryExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "ExplicitBase" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "xvalue", +// CHECK-NEXT: "storageDuration": "full expression", + +// CHECK: "kind": "CXXBindTemporaryExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "ExplicitBase" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", + +// CHECK: "kind": "CXXTemporaryObjectExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "ExplicitBase" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", +// CHECK-NEXT: "ctorType": { +// CHECK-NEXT: "qualType": "void (const char *)" +// CHECK-NEXT: }, +// CHECK-NEXT: "list": true, +// CHECK-NEXT: "hadMultipleCandidates": true, +// CHECK-NEXT: "constructionKind": "complete", + +// CHECK: "kind": "ImplicitCastExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "const char *" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", +// CHECK-NEXT: "castKind": "ArrayToPointerDecay", + +// CHECK: "kind": "StringLiteral", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "const char[10]" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "lvalue", +// CHECK-NEXT: "value": "\"Move Ctor\"" + return Derived1{ExplicitBase{"Move Ctor"}}; +} + +struct ImplicitBase { + ImplicitBase(const char *) { } + ImplicitBase(const ImplicitBase &) {} + ImplicitBase(ImplicitBase &&) {} + ImplicitBase &operator=(const ImplicitBase &) { return *this; } + ImplicitBase &operator=(ImplicitBase &&) { return *this; } + ~ImplicitBase() { } +}; + +struct Derived2 : ImplicitBase {}; + +Derived2 makeDerived2() { +// CHECK: "kind": "FunctionDecl", +// CHECK: "name": "makeDerived2", + +// CHECK: "kind": "CompoundStmt", + +// CHECK: "kind": "ReturnStmt", + +// CHECK: "kind": "ExprWithCleanups", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "Derived2" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", +// CHECK-NEXT: "cleanupsHaveSideEffects": true, + +// CHECK: "kind": "CXXFunctionalCastExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "Derived2" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", +// CHECK-NEXT: "castKind": "NoOp", + +// CHECK: "kind": "CXXBindTemporaryExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "Derived2" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", + +// CHECK: "kind": "InitListExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "Derived2" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", + +// CHECK: "kind": "CXXConstructExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "ImplicitBase" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", +// CHECK-NEXT: "ctorType": { +// CHECK-NEXT: "qualType": "void (const char *)" +// CHECK-NEXT: }, +// CHECK-NEXT: "list": true, +// CHECK-NEXT: "hadMultipleCandidates": true, +// CHECK-NEXT: "constructionKind": "non-virtual base", + +// CHECK: "kind": "ImplicitCastExpr", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "const char *" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "prvalue", +// CHECK-NEXT: "castKind": "ArrayToPointerDecay", + +// CHECK: "kind": "StringLiteral", +// CHECK: "type": { +// CHECK-NEXT: "qualType": "const char[8]" +// CHECK-NEXT: }, +// CHECK-NEXT: "valueCategory": "lvalue", +// CHECK-NEXT: "value": "\"No Ctor\"" + return Derived2{{"No Ctor"}}; +} + +// NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py +// using --filters=FunctionDecl,CompoundStmt,ReturnStmt,MaterializeTemporaryExpr,CXXBindTemporaryExpr,CXXTemporaryObjectExpr,ImplicitCastExpr,StringLiteralStringLiteral _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits