From 0c4483d9394896cd5d7057144a4cff2a4a03dd40 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 11 Jul 2018 21:07:04 +0000 Subject: [PATCH] Fix determination of whether one set of cvr-qualifiers is compatible with another in template argument deduction. We happened to typically get away with getting this wrong, because the cases where we'd produce a bogus deduction were caught by the final "deduced A is compatible with A" check. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336852 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateDeduction.cpp | 12 ++++++------ .../temp.deduct/temp.deduct.type/p1.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p1.cpp diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index fd4197ce2a..760207fece 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -1019,8 +1019,10 @@ DeduceTemplateArguments(Sema &S, return Sema::TDK_Success; } -/// Determine whether the parameter has qualifiers that are either -/// inconsistent with or a superset of the argument's qualifiers. +/// Determine whether the parameter has qualifiers that the argument +/// lacks. Put another way, determine whether there is no way to add +/// a deduced set of qualifiers to the ParamType that would result in +/// its qualifiers matching those of the ArgType. static bool hasInconsistentOrSupersetQualifiersOf(QualType ParamType, QualType ArgType) { Qualifiers ParamQs = ParamType.getQualifiers(); @@ -1044,10 +1046,8 @@ static bool hasInconsistentOrSupersetQualifiersOf(QualType ParamType, ParamQs.hasObjCLifetime()) return true; - // CVR qualifier superset. - return (ParamQs.getCVRQualifiers() != ArgQs.getCVRQualifiers()) && - ((ParamQs.getCVRQualifiers() | ArgQs.getCVRQualifiers()) - == ParamQs.getCVRQualifiers()); + // CVR qualifiers inconsistent or a superset. + return (ParamQs.getCVRQualifiers() & ~ArgQs.getCVRQualifiers()) != 0; } /// Compare types for equality with respect to possibly compatible diff --git a/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p1.cpp b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p1.cpp new file mode 100644 index 0000000000..33d8182ab1 --- /dev/null +++ b/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.type/p1.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -verify %s + +// an attempt is made to find template argument values that will make P, after +// substitution of the deduced values, compatible with A + +namespace cv_mismatch { + template struct X {}; + template void f(X); // expected-note {{cannot deduce a type for 'T' that would make 'const T' equal 'volatile int'}} + void g() { f(X()); } // expected-error {{no matching}} +} -- 2.40.0