]> granicus.if.org Git - clang/commitdiff
[Sema] Retain __restrict qualifiers when substituting a reference type.
authorErik Pilkington <erik.pilkington@gmail.com>
Thu, 20 Sep 2018 18:12:24 +0000 (18:12 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Thu, 20 Sep 2018 18:12:24 +0000 (18:12 +0000)
Fixes rdar://43760099

Differential revision: https://reviews.llvm.org/D52271

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342672 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/TreeTransform.h
test/SemaCXX/subst-restrict.cpp [new file with mode: 0644]

index f48f07d1e1d9d7581bbf48544f532fcd7b796db7..f8f6304085a7e6ca67fb984b019e8535a315d225 100644 (file)
@@ -4252,14 +4252,20 @@ QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
   // C++ [dcl.fct]p7:
   //   [When] adding cv-qualifications on top of the function type [...] the
   //   cv-qualifiers are ignored.
+  if (T->isFunctionType())
+    return T;
+
   // C++ [dcl.ref]p1:
   //   when the cv-qualifiers are introduced through the use of a typedef-name
   //   or decltype-specifier [...] the cv-qualifiers are ignored.
   // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
   // applied to a reference type.
-  // FIXME: This removes all qualifiers, not just cv-qualifiers!
-  if (T->isFunctionType() || T->isReferenceType())
-    return T;
+  if (T->isReferenceType()) {
+    // The only qualifier that applies to a reference type is restrict.
+    if (!Quals.hasRestrict())
+      return T;
+    Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
+  }
 
   // Suppress Objective-C lifetime qualifiers if they don't make sense for the
   // resulting type.
diff --git a/test/SemaCXX/subst-restrict.cpp b/test/SemaCXX/subst-restrict.cpp
new file mode 100644 (file)
index 0000000..aab6872
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+
+// expected-no-diagnostics
+
+template <class T> struct add_restrict {
+  typedef T __restrict type;
+};
+
+template <class T, class V> struct is_same {
+  static constexpr bool value = false;
+};
+
+template <class T> struct is_same<T, T> {
+  static constexpr bool value = true;
+};
+
+static_assert(is_same<int & __restrict, add_restrict<int &>::type>::value, "");
+static_assert(is_same<int(), add_restrict<int()>::type>::value, "");