From 931e0bd3319535542a58213bf854365a9fc03526 Mon Sep 17 00:00:00 2001 From: Sebastian Redl Date: Wed, 18 Nov 2009 20:55:52 +0000 Subject: [PATCH] Pretend destructors are const and volatile. This allows calling them with const and/or volatile objects. Fixes PR5548. llvm-svn: 89244 --- clang/lib/Sema/SemaOverload.cpp | 9 ++++++--- clang/test/CXX/special/class.dtor/p2.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 clang/test/CXX/special/class.dtor/p2.cpp diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 916fe5719220..a86b57c0d820 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -2090,8 +2090,11 @@ bool Sema::PerformCopyInitialization(Expr *&From, QualType ToType, ImplicitConversionSequence Sema::TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method) { QualType ClassType = Context.getTypeDeclType(Method->getParent()); - QualType ImplicitParamType - = Context.getCVRQualifiedType(ClassType, Method->getTypeQualifiers()); + // [class.dtor]p2: A destructor can be invoked for a const, volatile or + // const volatile object. + unsigned Quals = isa(Method) ? + Qualifiers::Const | Qualifiers::Volatile : Method->getTypeQualifiers(); + QualType ImplicitParamType = Context.getCVRQualifiedType(ClassType, Quals); // Set up the conversion sequence as a "bad" conversion, to allow us // to exit early. @@ -2106,7 +2109,7 @@ Sema::TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method) { assert(FromType->isRecordType()); - // The implicit object parmeter is has the type "reference to cv X", + // The implicit object parameter is has the type "reference to cv X", // where X is the class of which the function is a member // (C++ [over.match.funcs]p4). However, when finding an implicit // conversion sequence for the argument, we are not allowed to diff --git a/clang/test/CXX/special/class.dtor/p2.cpp b/clang/test/CXX/special/class.dtor/p2.cpp new file mode 100644 index 000000000000..c0e878fed2a5 --- /dev/null +++ b/clang/test/CXX/special/class.dtor/p2.cpp @@ -0,0 +1,7 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +// PR5548 +struct A {~A();}; +void a(const A* x) { + x->~A(); +}