AndersRonnholm created this revision. AndersRonnholm added a project: clang-tools-extra.
Fixes assert reported in https://bugs.llvm.org/show_bug.cgi?id=33660 Repository: rL LLVM https://reviews.llvm.org/D36670 Files: clang-tidy/misc/MisplacedWideningCastCheck.cpp test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp Index: test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp =================================================================== --- test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp +++ test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp @@ -56,3 +56,9 @@ return (long)a * 1000; } } + +// Shall not generate an assert. https://bugs.llvm.org/show_bug.cgi?id=33660 +template <class> class A { + enum Type {}; + static char *m_fn1() { char p = (Type)(&p - m_fn1()); } +}; Index: clang-tidy/misc/MisplacedWideningCastCheck.cpp =================================================================== --- clang-tidy/misc/MisplacedWideningCastCheck.cpp +++ clang-tidy/misc/MisplacedWideningCastCheck.cpp @@ -192,6 +192,10 @@ if (Calc->getLocStart().isMacroID()) return; + if (Cast->isTypeDependent() || Cast->isValueDependent() || + Calc->isTypeDependent() || Calc->isValueDependent()) + return; + ASTContext &Context = *Result.Context; QualType CastType = Cast->getType();
Index: test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp =================================================================== --- test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp +++ test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp @@ -56,3 +56,9 @@ return (long)a * 1000; } } + +// Shall not generate an assert. https://bugs.llvm.org/show_bug.cgi?id=33660 +template <class> class A { + enum Type {}; + static char *m_fn1() { char p = (Type)(&p - m_fn1()); } +}; Index: clang-tidy/misc/MisplacedWideningCastCheck.cpp =================================================================== --- clang-tidy/misc/MisplacedWideningCastCheck.cpp +++ clang-tidy/misc/MisplacedWideningCastCheck.cpp @@ -192,6 +192,10 @@ if (Calc->getLocStart().isMacroID()) return; + if (Cast->isTypeDependent() || Cast->isValueDependent() || + Calc->isTypeDependent() || Calc->isValueDependent()) + return; + ASTContext &Context = *Result.Context; QualType CastType = Cast->getType();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits