]> granicus.if.org Git - clang/commitdiff
PR14838: When a member reference is bound to a temporary, don't forget to
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 8 Jan 2013 00:08:23 +0000 (00:08 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 8 Jan 2013 00:08:23 +0000 (00:08 +0000)
perform the semantic checks associated with the destruction of that temporary.
It'll be destroyed at the end of the constructor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171818 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/SemaCXX/member-init.cpp

index 6796f9a5500592f1a74eda5321cbca4bd3117abf..111f81e44995df5f2fb03ed5ed7e5136ec232e6b 100644 (file)
@@ -4290,7 +4290,7 @@ getAssignmentAction(const InitializedEntity &Entity) {
   llvm_unreachable("Invalid EntityKind!");
 }
 
-/// \brief Whether we should binding a created object as a temporary when
+/// \brief Whether we should bind a created object as a temporary when
 /// initializing the given entity.
 static bool shouldBindAsTemporary(const InitializedEntity &Entity) {
   switch (Entity.getKind()) {
@@ -4320,7 +4320,6 @@ static bool shouldBindAsTemporary(const InitializedEntity &Entity) {
 /// created for that initialization, requires destruction.
 static bool shouldDestroyTemporary(const InitializedEntity &Entity) {
   switch (Entity.getKind()) {
-    case InitializedEntity::EK_Member:
     case InitializedEntity::EK_Result:
     case InitializedEntity::EK_New:
     case InitializedEntity::EK_Base:
@@ -4331,6 +4330,7 @@ static bool shouldDestroyTemporary(const InitializedEntity &Entity) {
     case InitializedEntity::EK_LambdaCapture:
       return false;
 
+    case InitializedEntity::EK_Member:
     case InitializedEntity::EK_Variable:
     case InitializedEntity::EK_Parameter:
     case InitializedEntity::EK_Temporary:
index a13941fce5d8e887c3862b38f9a48625b5a22b84..19e8e7597e850e224b0ad3d139e088edd548ada4 100644 (file)
@@ -73,3 +73,19 @@ namespace PR10578 {
   } catch(...) {
   }
 }
+
+namespace PR14838 {
+  struct base { ~base() {} };
+  class function : base {
+    ~function() {} // expected-note {{implicitly declared private here}}
+  public:
+    function(...) {}
+  };
+  struct thing {};
+  struct another {
+    another() : r(thing()) {}
+    // expected-error@-1 {{temporary of type 'const PR14838::function' has private destructor}}
+    // expected-warning@-2 {{binding reference member 'r' to a temporary value}}
+    const function &r; // expected-note {{reference member declared here}}
+  } af;
+}