r231054 - Sema: Caught exception objects should be unqualified
David Majnemer
david.majnemer at gmail.com
Mon Mar 2 20:38:34 PST 2015
Author: majnemer
Date: Mon Mar 2 22:38:34 2015
New Revision: 231054
URL: http://llvm.org/viewvc/llvm-project?rev=231054&view=rev
Log:
Sema: Caught exception objects should be unqualified
The exception object should be unqualified. Using a qualified exception
object results in the wrong copy constructor getting called when the
catch handler executes.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/exceptions.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=231054&r1=231053&r2=231054&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Mar 2 22:38:34 2015
@@ -11933,7 +11933,7 @@ VarDecl *Sema::BuildExceptionDeclaration
//
// 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);
Modified: cfe/trunk/test/SemaCXX/exceptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/exceptions.cpp?rev=231054&r1=231053&r2=231054&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/exceptions.cpp (original)
+++ cfe/trunk/test/SemaCXX/exceptions.cpp Mon Mar 2 22:38:34 2015
@@ -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}}
+ }
+}
+}
More information about the cfe-commits
mailing list