Author: rsmith Date: Fri Oct 28 14:54:43 2016 New Revision: 285437 URL: http://llvm.org/viewvc/llvm-project?rev=285437&view=rev Log: PR30831: Teach template type diffing to cope with TemplateSpecializationTypes that desugar to non-TSTs (such as injected-class-names).
Modified: cfe/trunk/lib/AST/ASTDiagnostic.cpp cfe/trunk/test/Misc/diag-template-diffing.cpp Modified: cfe/trunk/lib/AST/ASTDiagnostic.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDiagnostic.cpp?rev=285437&r1=285436&r2=285437&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTDiagnostic.cpp (original) +++ cfe/trunk/lib/AST/ASTDiagnostic.cpp Fri Oct 28 14:54:43 2016 @@ -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; } Modified: cfe/trunk/test/Misc/diag-template-diffing.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/diag-template-diffing.cpp?rev=285437&r1=285436&r2=285437&view=diff ============================================================================== --- cfe/trunk/test/Misc/diag-template-diffing.cpp (original) +++ cfe/trunk/test/Misc/diag-template-diffing.cpp Fri Oct 28 14:54:43 2016 @@ -1492,3 +1492,8 @@ void run(A_reg<float> reg, A_ptr<float> // 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>(); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits