[cfe-commits] r171818 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/SemaCXX/member-init.cpp

Richard Smith richard-llvm at metafoo.co.uk
Mon Jan 7 16:08:23 PST 2013


Author: rsmith
Date: Mon Jan  7 18:08:23 2013
New Revision: 171818

URL: http://llvm.org/viewvc/llvm-project?rev=171818&view=rev
Log:
PR14838: When a member reference is bound to a temporary, don't forget to
perform the semantic checks associated with the destruction of that temporary.
It'll be destroyed at the end of the constructor.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/member-init.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=171818&r1=171817&r2=171818&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Jan  7 18:08:23 2013
@@ -4290,7 +4290,7 @@
   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 @@
 /// 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 @@
     case InitializedEntity::EK_LambdaCapture:
       return false;
 
+    case InitializedEntity::EK_Member:
     case InitializedEntity::EK_Variable:
     case InitializedEntity::EK_Parameter:
     case InitializedEntity::EK_Temporary:

Modified: cfe/trunk/test/SemaCXX/member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-init.cpp?rev=171818&r1=171817&r2=171818&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-init.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-init.cpp Mon Jan  7 18:08:23 2013
@@ -73,3 +73,19 @@
   } 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 at -1 {{temporary of type 'const PR14838::function' has private destructor}}
+    // expected-warning at -2 {{binding reference member 'r' to a temporary value}}
+    const function &r; // expected-note {{reference member declared here}}
+  } af;
+}





More information about the cfe-commits mailing list