From 401997db928eb5aff56b8daaf4cd676e102b05d7 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Tue, 5 Mar 2019 14:09:57 +0000 Subject: [PATCH] [clang-tidy] Fix bugprone-string-constructor crash llvm-svn: 355401 --- clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp | 3 ++- clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp index 3a4e75b..a4b83ad 100644 --- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp @@ -138,7 +138,8 @@ void StringConstructorCheck::check(const MatchFinder::MatchResult &Result) { } } else if (const auto *Ptr = Result.Nodes.getNodeAs("from-ptr")) { Expr::EvalResult ConstPtr; - if (Ptr->EvaluateAsRValue(ConstPtr, Ctx) && + if (!Ptr->isInstantiationDependent() && + Ptr->EvaluateAsRValue(ConstPtr, Ctx) && ((ConstPtr.Val.isInt() && ConstPtr.Val.getInt().isNullValue()) || (ConstPtr.Val.isLValue() && ConstPtr.Val.isNullPointer()))) { diag(Loc, "constructing string from nullptr is undefined behaviour"); diff --git a/clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp b/clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp index 3ab4f42..9e11a32 100644 --- a/clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp +++ b/clang-tools-extra/test/clang-tidy/bugprone-string-constructor.cpp @@ -65,3 +65,11 @@ void Valid() { std::string s2("test", 3); std::string s3("test"); } + +namespace instantiation_dependent_exprs { +template +struct S { + bool x; + std::string f() { return x ? "a" : "b"; } +}; +} -- 2.7.4