[PATCH] D20923: [Sema] Fix a crash on invalid where invalid defaulted function is called

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 2 10:03:38 PDT 2016


erik.pilkington created this revision.
erik.pilkington added a reviewer: rsmith.
erik.pilkington added a subscriber: cfe-commits.

Previously, clang would crash on the test case below, because it misinterprets the `operator=(bool)` call as a move assignment operator.


http://reviews.llvm.org/D20923

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/cxx0x-defaulted-functions.cpp

Index: test/SemaCXX/cxx0x-defaulted-functions.cpp
===================================================================
--- test/SemaCXX/cxx0x-defaulted-functions.cpp
+++ test/SemaCXX/cxx0x-defaulted-functions.cpp
@@ -196,3 +196,15 @@
   A<int> a;
   B<int> b; // expected-note {{here}}
 }
+
+namespace PR27941 {
+struct ExplicitBool {
+  ExplicitBool &operator=(bool) = default; // expected-error{{only special member functions may be defaulted}}
+  int member;
+};
+
+int fn() {
+  ExplicitBool t;
+  t = true;
+}
+}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13005,7 +13005,7 @@
       if (MethodDecl->isDefaulted() && !MethodDecl->isDeleted()) {
         if (MethodDecl->isCopyAssignmentOperator())
           DefineImplicitCopyAssignment(Loc, MethodDecl);
-        else
+        else if (MethodDecl->isMoveAssignmentOperator())
           DefineImplicitMoveAssignment(Loc, MethodDecl);
       }
     } else if (isa<CXXConversionDecl>(MethodDecl) &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20923.59409.patch
Type: text/x-patch
Size: 1062 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160602/d6a91f00/attachment.bin>


More information about the cfe-commits mailing list