From 9b6e2d209cc2931a9bb2ae51e744a8698b54db73 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 22 Oct 2008 00:38:21 +0000 Subject: [PATCH] Fix a thinko in the qualification-conversion check when the qualificaitons are disjoint, and add some overloading-based tests of qualification conversions git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57942 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Type.h | 2 +- lib/Sema/SemaOverload.cpp | 2 +- test/SemaCXX/overload-call.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index b11f711255..07eae4427a 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -178,7 +178,7 @@ public: bool isAtLeastAsQualifiedAs(QualType Other) const { unsigned MyQuals = this->getCVRQualifiers(); unsigned OtherQuals = Other.getCVRQualifiers(); - return MyQuals | OtherQuals == MyQuals; + return (MyQuals | OtherQuals) == MyQuals; } /// operator==/!= - Indicate whether the specified types and qualifiers are diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 2696c98523..6d01709c5b 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -685,7 +685,7 @@ Sema::IsQualificationConversion(QualType FromType, QualType ToType) // -- for every j > 0, if const is in cv 1,j then const is in cv // 2,j, and similarly for volatile. - if (FromType.isMoreQualifiedThan(ToType)) + if (!ToType.isAtLeastAsQualifiedAs(FromType)) return false; // -- if the cv 1,j and cv 2,j are different, then const is in diff --git a/test/SemaCXX/overload-call.cpp b/test/SemaCXX/overload-call.cpp index 311e3d0d3e..165ee60c84 100644 --- a/test/SemaCXX/overload-call.cpp +++ b/test/SemaCXX/overload-call.cpp @@ -135,3 +135,32 @@ void test_multiparm(long lv, short sv, int iv) { double* dp2 = multiparm(iv, sv, sv); multiparm(sv, sv, lv); // expected-error {{ call to 'multiparm' is ambiguous; candidates are: }} } + +// Test overloading based on qualification vs. no qualification +// conversion. +int* quals1(int const * p); +char* quals1(int * p); + +int* quals2(int const * const * pp); +char* quals2(int * * pp); + +int* quals3(int const * * const * ppp); +char* quals3(int *** ppp); + +void test_quals(int * p, int * * pp, int * * * ppp) { + char* q1 = quals1(p); + char* q2 = quals2(pp); + char* q3 = quals3(ppp); +} + +// Test overloading based on qualification ranking (C++ 13.3.2)p3. +int* quals_rank1(int const * p); +float* quals_rank1(int const volatile *p); + +int* quals_rank2(int const * const * pp); +float* quals_rank2(int * const * pp); + +void test_quals_ranking(int * p, int volatile *pq, int * * pp, int * * * ppp) { + // int* q1 = quals_rank1(p); + float* q2 = quals_rank1(pq); +} -- 2.40.0