[cfe-commits] r112390 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/deduction.cpp

John McCall rjmccall at apple.com
Sat Aug 28 15:14:41 PDT 2010


Author: rjmccall
Date: Sat Aug 28 17:14:41 2010
New Revision: 112390

URL: http://llvm.org/viewvc/llvm-project?rev=112390&view=rev
Log:
When perform exact-qualifier-match template argument deduction,
properly account for the possibility that certain opaque types
might be more qualified than they appear.  Fixes PR7708.


Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/SemaTemplate/deduction.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=112390&r1=112389&r2=112390&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Sat Aug 28 17:14:41 2010
@@ -350,6 +350,29 @@
   return Sema::TDK_Success;
 }
 
+/// \brief Determines whether the given type is an opaque type that
+/// might be more qualified when instantiated.
+static bool IsPossiblyOpaquelyQualifiedType(QualType T) {
+  switch (T->getTypeClass()) {
+  case Type::TypeOfExpr:
+  case Type::TypeOf:
+  case Type::DependentName:
+  case Type::Decltype:
+  case Type::UnresolvedUsing:
+    return true;
+
+  case Type::ConstantArray:
+  case Type::IncompleteArray:
+  case Type::VariableArray:
+  case Type::DependentSizedArray:
+    return IsPossiblyOpaquelyQualifiedType(
+                                      cast<ArrayType>(T)->getElementType());
+
+  default:
+    return false;
+  }
+}
+
 /// \brief Deduce the template arguments by comparing the parameter type and
 /// the argument type (C++ [temp.deduct.type]).
 ///
@@ -474,7 +497,7 @@
     if (TDF & TDF_ParamWithReferenceType) {
       if (Param.isMoreQualifiedThan(Arg))
         return Sema::TDK_NonDeducedMismatch;
-    } else {
+    } else if (!IsPossiblyOpaquelyQualifiedType(Param)) {
       if (Param.getCVRQualifiers() != Arg.getCVRQualifiers())
         return Sema::TDK_NonDeducedMismatch;
     }

Modified: cfe/trunk/test/SemaTemplate/deduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction.cpp?rev=112390&r1=112389&r2=112390&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction.cpp Sat Aug 28 17:14:41 2010
@@ -121,3 +121,16 @@
     foo(a);
   }
 }
+
+// PR7708
+namespace test2 {
+  template<typename T> struct Const { typedef void const type; };
+
+  template<typename T> void f(T, typename Const<T>::type*);
+  template<typename T> void f(T, void const *);
+
+  void test() {
+    void *p = 0;
+    f(0, p);
+  }
+}





More information about the cfe-commits mailing list