]> granicus.if.org Git - clang/commitdiff
Sema: Caught exception objects should be unqualified
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 3 Mar 2015 04:38:34 +0000 (04:38 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 3 Mar 2015 04:38:34 +0000 (04:38 +0000)
The exception object should be unqualified.  Using a qualified exception
object results in the wrong copy constructor getting called when the
catch handler executes.

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

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/exceptions.cpp

index c78f214fbca6682cf2eec2c5b388c084a01071ec..4b635c0ed79a392e82bb4ab5f857ec6065cbf087 100644 (file)
@@ -11933,7 +11933,7 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S,
       //
       // We just pretend to initialize the object with itself, then make sure
       // it can be destroyed later.
-      QualType initType = ExDeclType;
+      QualType initType = Context.getExceptionObjectType(ExDeclType);
 
       InitializedEntity entity =
         InitializedEntity::InitializeVariable(ExDecl);
index 5f4ff23eb779a3f9cfc01e5d646f3f7ffa60270b..6ac51b32e4873d9c3e1041bb147d04c42d7b875d 100644 (file)
@@ -146,7 +146,7 @@ namespace Decay {
 
 void rval_ref() throw (int &&); // expected-error {{rvalue reference type 'int &&' is not allowed in exception specification}} expected-warning {{C++11}}
 
-namespace ConstVolatile {
+namespace ConstVolatileThrow {
 struct S {
   S() {}         // expected-note{{candidate constructor not viable}}
   S(const S &s); // expected-note{{candidate constructor not viable}}
@@ -158,3 +158,22 @@ void f() {
   throw CVS(); // expected-error{{no matching constructor for initialization}}
 }
 }
+
+namespace ConstVolatileCatch {
+struct S {
+  S() {}
+  S(const volatile S &s);
+
+private:
+  S(const S &s); // expected-note {{declared private here}}
+};
+
+void f();
+
+void g() {
+  try {
+    f();
+  } catch (volatile S s) { // expected-error {{calling a private constructor}}
+  }
+}
+}