]> granicus.if.org Git - clang/commitdiff
Don't reject __restrict applied to a dependent type; it might instantiate to a pointe...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 27 Mar 2013 23:36:39 +0000 (23:36 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 27 Mar 2013 23:36:39 +0000 (23:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178198 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaType.cpp
lib/Sema/TreeTransform.h
test/SemaTemplate/fun-template-def.cpp

index e9ccbecaba5b7b7eed6e63b7107e846e617f3c26..95df969ebaa240218ecd13addc7cb1e37c858c06 100644 (file)
@@ -1106,7 +1106,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
             << 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();
index 1dde87d2e6d25377e284b8c695483365ad95910d..1e424b6076b79adbd43edae6855b101d25c61106 100644 (file)
@@ -3396,7 +3396,9 @@ TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
   }
   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.
   }
 
index 04277812187f8c810029ca1484aeffe54cdff687..f57a045649a7379d50c7d1b4615932cc4799d988 100644 (file)
@@ -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'}}
+}