]> granicus.if.org Git - clang/commitdiff
PR30831: Teach template type diffing to cope with TemplateSpecializationTypes
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 28 Oct 2016 19:54:43 +0000 (19:54 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 28 Oct 2016 19:54:43 +0000 (19:54 +0000)
that desugar to non-TSTs (such as injected-class-names).

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

lib/AST/ASTDiagnostic.cpp
test/Misc/diag-template-diffing.cpp

index 590defb7ee590ce0ed4f6b4653c8a3fce44b040e..03e6115a0dba1391828f016fb8ebbee4dd0df7d2 100644 (file)
@@ -936,6 +936,9 @@ class TemplateDiff {
         ++(*this);
       }
 
+      /// Return true if the iterator is non-singular.
+      bool isValid() const { return TST; }
+
       /// isEnd - Returns true if the iterator is one past the end.
       bool isEnd() const {
         assert(TST && "InternalIterator is invalid with a null TST.");
@@ -995,21 +998,21 @@ class TemplateDiff {
       }
     };
 
-    bool UseDesugaredIterator;
     InternalIterator SugaredIterator;
     InternalIterator DesugaredIterator;
 
   public:
     TSTiterator(ASTContext &Context, const TemplateSpecializationType *TST)
-        : UseDesugaredIterator(TST->isSugared() && !TST->isTypeAlias()),
-          SugaredIterator(TST),
+        : SugaredIterator(TST),
           DesugaredIterator(
-              GetTemplateSpecializationType(Context, TST->desugar())) {}
+              (TST->isSugared() && !TST->isTypeAlias())
+                  ? GetTemplateSpecializationType(Context, TST->desugar())
+                  : nullptr) {}
 
     /// &operator++ - Increment the iterator to the next template argument.
     TSTiterator &operator++() {
       ++SugaredIterator;
-      if (UseDesugaredIterator)
+      if (DesugaredIterator.isValid())
         ++DesugaredIterator;
       return *this;
     }
@@ -1032,12 +1035,12 @@ class TemplateDiff {
     /// hasDesugaredTA - Returns true if there is another TemplateArgument
     /// available.
     bool hasDesugaredTA() const {
-      return UseDesugaredIterator && !DesugaredIterator.isEnd();
+      return DesugaredIterator.isValid() && !DesugaredIterator.isEnd();
     }
 
     /// getDesugaredTA - Returns the desugared TemplateArgument.
     reference getDesugaredTA() const {
-      assert(UseDesugaredIterator &&
+      assert(DesugaredIterator.isValid() &&
              "Desugared TemplateArgument should not be used.");
       return *DesugaredIterator;
     }
index a4f29cc8c7f0b69f067001756ae212b070f33a00..78083989928244430bd0148ae261ba002789b23f 100644 (file)
@@ -1492,3 +1492,8 @@ void run(A_reg<float> reg, A_ptr<float> ptr, A_ref<float> ref) {
 // CHECK-NOELIDE-NOTREE: {{[0-9]*}} errors generated.
 // CHECK-ELIDE-TREE: {{[0-9]*}} errors generated.
 // CHECK-NOELIDE-TREE: {{[0-9]*}} errors generated.
+
+namespace pr30831 {
+  template <typename T> struct A { static A<T> const a; };
+  template <typename T> A<T> A<T>::a = A<T>();
+}