mizvekov created this revision.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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 <mizve...@gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127075

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


Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===================================================================
--- clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -98,7 +98,7 @@
   A1(const A1 &);
   A1(A1 &&) = delete;
   // expected-note@-1 2{{'A1' has been explicitly marked deleted here}}
-  // cxx11_2b-note@-2  {{'A1' has been explicitly marked deleted here}}
+  // cxx11_2b-note@-2 3{{'A1' has been explicitly marked deleted here}}
 };
 void test1() {
   try {
@@ -132,10 +132,10 @@
 namespace PR54341 {
 void test4(A1 a) {
   void f(decltype((throw a, 0)));
-  // expected-warning@-1 {{has no effect}}
+  // expected-error@-1 {{call to deleted constructor of 
'test_throw_parameter::A1'}}
 
   void g(int = decltype(throw a, 0){});
-  // expected-warning@-1 {{has no effect}}
+  // expected-error@-1 {{call to deleted constructor of 
'test_throw_parameter::A1'}}
 }
 
 void test5(A1 a, int = decltype(throw a, 0){}) {}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -845,8 +845,7 @@
 
             if (S->getFlags() &
                 (Scope::FnScope | Scope::ClassScope | Scope::BlockScope |
-                 Scope::FunctionPrototypeScope | Scope::ObjCMethodScope |
-                 Scope::TryScope))
+                 Scope::ObjCMethodScope | Scope::TryScope))
               break;
           }
         }


Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===================================================================
--- clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -98,7 +98,7 @@
   A1(const A1 &);
   A1(A1 &&) = delete;
   // expected-note@-1 2{{'A1' has been explicitly marked deleted here}}
-  // cxx11_2b-note@-2  {{'A1' has been explicitly marked deleted here}}
+  // cxx11_2b-note@-2 3{{'A1' has been explicitly marked deleted here}}
 };
 void test1() {
   try {
@@ -132,10 +132,10 @@
 namespace PR54341 {
 void test4(A1 a) {
   void f(decltype((throw a, 0)));
-  // expected-warning@-1 {{has no effect}}
+  // expected-error@-1 {{call to deleted constructor of 'test_throw_parameter::A1'}}
 
   void g(int = decltype(throw a, 0){});
-  // expected-warning@-1 {{has no effect}}
+  // expected-error@-1 {{call to deleted constructor of 'test_throw_parameter::A1'}}
 }
 
 void test5(A1 a, int = decltype(throw a, 0){}) {}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -845,8 +845,7 @@
 
             if (S->getFlags() &
                 (Scope::FnScope | Scope::ClassScope | Scope::BlockScope |
-                 Scope::FunctionPrototypeScope | Scope::ObjCMethodScope |
-                 Scope::TryScope))
+                 Scope::ObjCMethodScope | Scope::TryScope))
               break;
           }
         }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D127075: ... Matheus Izvekov via Phabricator via cfe-commits

Reply via email to