r178198 - Don't reject __restrict applied to a dependent type; it might instantiate to a pointer or reference type.

Richard Smith richard-llvm at metafoo.co.uk
Wed Mar 27 16:36:40 PDT 2013


Author: rsmith
Date: Wed Mar 27 18:36:39 2013
New Revision: 178198

URL: http://llvm.org/viewvc/llvm-project?rev=178198&view=rev
Log:
Don't reject __restrict applied to a dependent type; it might instantiate to a pointer or reference type.

Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/SemaTemplate/fun-template-def.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=178198&r1=178197&r2=178198&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Mar 27 18:36:39 2013
@@ -1106,7 +1106,7 @@ static QualType ConvertDeclSpecToType(Ty
             << EltTy << DS.getSourceRange();
           TypeQuals &= ~DeclSpec::TQ_restrict; // Remove the restrict qualifier.
         }
-      } else {
+      } else if (!Result->isDependentType()) {
         S.Diag(DS.getRestrictSpecLoc(),
                diag::err_typecheck_invalid_restrict_not_pointer)
           << Result << DS.getSourceRange();

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=178198&r1=178197&r2=178198&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Wed Mar 27 18:36:39 2013
@@ -3396,7 +3396,9 @@ TreeTransform<Derived>::TransformQualifi
   }
   if (!Quals.empty()) {
     Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
-    TLB.push<QualifiedTypeLoc>(Result);
+    // BuildQualifiedType might not add qualifiers if they are invalid.
+    if (Result.hasLocalQualifiers())
+      TLB.push<QualifiedTypeLoc>(Result);
     // No location information to preserve.
   }
 

Modified: cfe/trunk/test/SemaTemplate/fun-template-def.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/fun-template-def.cpp?rev=178198&r1=178197&r2=178198&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/fun-template-def.cpp (original)
+++ cfe/trunk/test/SemaTemplate/fun-template-def.cpp Wed Mar 27 18:36:39 2013
@@ -46,3 +46,11 @@ T f1(T t1, U u1, int i1)
 
   return u1;
 }
+
+template<typename T>
+void f2(__restrict T x) {} // expected-note {{substitution failure [with T = int]: pointer to function type 'int' may not be 'restrict' qualified}}
+
+void f3() {
+  f2<int*>(0);
+  f2<int>(0); // expected-error {{no matching function for call to 'f2'}}
+}





More information about the cfe-commits mailing list