[clang-tools-extra] r355401 - [clang-tidy] Fix bugprone-string-constructor crash

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 5 06:09:57 PST 2019


Author: alexfh
Date: Tue Mar  5 06:09:57 2019
New Revision: 355401

URL: http://llvm.org/viewvc/llvm-project?rev=355401&view=rev
Log:
[clang-tidy] Fix bugprone-string-constructor crash

Modified:
    clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp?rev=355401&r1=355400&r2=355401&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp Tue Mar  5 06:09:57 2019
@@ -138,7 +138,8 @@ void StringConstructorCheck::check(const
     }
   } else if (const auto *Ptr = Result.Nodes.getNodeAs<Expr>("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");

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp?rev=355401&r1=355400&r2=355401&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-string-constructor.cpp Tue Mar  5 06:09:57 2019
@@ -65,3 +65,11 @@ void Valid() {
   std::string s2("test", 3);
   std::string s3("test");
 }
+
+namespace instantiation_dependent_exprs {
+template<typename T>
+struct S {
+  bool x;
+  std::string f() { return x ? "a" : "b"; }
+};
+}




More information about the cfe-commits mailing list