[clang] 43ef17c - [clang] P2266: apply move elision rules on throw expr nested in function prototypes

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 6 15:08:33 PDT 2022


Author: Matheus Izvekov
Date: 2022-06-07T00:08:24+02:00
New Revision: 43ef17cac172229f8b176b42cf0e5ae6c82adbde

URL: https://github.com/llvm/llvm-project/commit/43ef17cac172229f8b176b42cf0e5ae6c82adbde
DIFF: https://github.com/llvm/llvm-project/commit/43ef17cac172229f8b176b42cf0e5ae6c82adbde.diff

LOG: [clang] P2266: apply move elision rules on throw expr nested in function prototypes

Our rules to determine if the throw expression are within the variable
scope were giving a false negative result in case the throw expression
would appear within a decltype in a nested function declaration.

Per P2266R3, the relevant rule is: [expr.prim.id.unqual]/2
```
    if the id-expression (possibly parenthesized) is the operand of a throw-expression, and names an implicitly movable entity that belongs to a scope that does not contain the compound-statement of the innermost lambda-expression, try-block , or function-try-block (if any) whose compound-statement or ctor-initializer encloses the throw-expression.
```

This fixes PR54341.

Signed-off-by: Matheus Izvekov <mizvekov at gmail.com>

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D127075

Added: 
    

Modified: 
    clang/lib/Sema/SemaExprCXX.cpp
    clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 27ec863e7a35e..6c2c61639be77 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -843,10 +843,10 @@ Sema::ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *Ex) {
               break;
             }
 
+            // FIXME: Many of the scope checks here seem incorrect.
             if (S->getFlags() &
                 (Scope::FnScope | Scope::ClassScope | Scope::BlockScope |
-                 Scope::FunctionPrototypeScope | Scope::ObjCMethodScope |
-                 Scope::TryScope))
+                 Scope::ObjCMethodScope | Scope::TryScope))
               break;
           }
         }

diff  --git a/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp b/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
index d7b52c561a547..975557c5187bb 100644
--- a/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
+++ b/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -98,7 +98,7 @@ struct A1 {
   A1(const A1 &);
   A1(A1 &&) = delete;
   // expected-note at -1 2{{'A1' has been explicitly marked deleted here}}
-  // cxx11_2b-note at -2  {{'A1' has been explicitly marked deleted here}}
+  // cxx11_2b-note at -2 3{{'A1' has been explicitly marked deleted here}}
 };
 void test1() {
   try {
@@ -132,10 +132,10 @@ void test3(A1 a) try {
 namespace PR54341 {
 void test4(A1 a) {
   void f(decltype((throw a, 0)));
-  // expected-warning at -1 {{has no effect}}
+  // expected-error at -1 {{call to deleted constructor of 'test_throw_parameter::A1'}}
 
   void g(int = decltype(throw a, 0){});
-  // expected-warning at -1 {{has no effect}}
+  // expected-error at -1 {{call to deleted constructor of 'test_throw_parameter::A1'}}
 }
 
 void test5(A1 a, int = decltype(throw a, 0){}) {}


        


More information about the cfe-commits mailing list