]> granicus.if.org Git - clang/commitdiff
Use ConstStringRef facility for getCustomDiagID() safety
authorAlp Toker <alp@nuanti.com>
Mon, 27 Jan 2014 04:22:22 +0000 (04:22 +0000)
committerAlp Toker <alp@nuanti.com>
Mon, 27 Jan 2014 04:22:22 +0000 (04:22 +0000)
This is one of various functions in clang that don't handle arbitrary strings
well and can benefit from compile-time safety checks.

Also fixes an off-by-one error that caused one additional null byte to get
added to the end of custom diagnostic descriptions. ConstStringRef handles
tricky details like that for us now.

Requires supporting changes in LLVM r200187.

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

include/clang/Basic/Diagnostic.h
include/clang/Basic/LLVM.h

index d5452d74f68eba4b951e2ec48aa8292f2c048891..a81550a69f6beb12430e6d5353a6cd89d0f1856a 100644 (file)
@@ -595,10 +595,8 @@ public:
   ///
   /// \param FormatString A fixed diagnostic format string that will be hashed
   /// and mapped to a unique DiagID.
-  template <unsigned N>
-  unsigned getCustomDiagID(Level L, const char (&FormatString)[N]) {
-    return Diags->getCustomDiagID((DiagnosticIDs::Level)L,
-                                  StringRef(FormatString, N));
+  unsigned getCustomDiagID(Level L, ConstStringRef FormatString) {
+    return Diags->getCustomDiagID((DiagnosticIDs::Level)L, FormatString);
   }
 
   /// \brief Converts a diagnostic argument (as an intptr_t) into the string
index 306c75e57a9f75fd22192b7502370edf82d95290..166c61cef21286da51653ed3478cd14e4f212cb5 100644 (file)
@@ -27,6 +27,7 @@
 namespace llvm {
   // ADT's.
   class StringRef;
+  class ConstStringRef;
   class Twine;
   template<typename T> class ArrayRef;
   template<typename T> class OwningPtr;
@@ -61,6 +62,7 @@ namespace clang {
   using llvm::None;
   using llvm::Optional;
   using llvm::StringRef;
+  using llvm::ConstStringRef;
   using llvm::Twine;
   using llvm::ArrayRef;
   using llvm::OwningPtr;