StringRef: Extend constexpr capabilities and introduce ConstStringRef
authorAlp Toker <alp@nuanti.com>
Mon, 27 Jan 2014 04:07:17 +0000 (04:07 +0000)
committerAlp Toker <alp@nuanti.com>
Mon, 27 Jan 2014 04:07:17 +0000 (04:07 +0000)
commitbad91954cf7c2caae19728bed33729a390d88725
tree25de33597852132787915526cf83f9a8524ae09b
parent1943ce9b6e16d58ec7341f4c1b4fdca2e4f327e9
StringRef: Extend constexpr capabilities and introduce ConstStringRef

(1) Add llvm_expect(), an asserting macro that can be evaluated as a constexpr
    expression as well as a runtime assert or compiler hint in release builds. This
    technique can be used to construct functions that are both unevaluated and
    compiled depending on usage.

(2) Update StringRef using llvm_expect() to preserve runtime assertions while
    extending the same checks to static asserts in C++11 builds that support the
    feature.

(3) Introduce ConstStringRef, a strong subclass of StringRef that references
    compile-time constant strings. It's convertible to, but not from, ordinary
    StringRef and thus can be used to add compile-time safety to various interfaces
    in LLVM and clang that only accept fixed inputs such as diagnostic format
    strings that tend to get misused.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200187 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/StringRef.h
include/llvm/Support/ErrorHandling.h
lib/Support/ErrorHandling.cpp
unittests/ADT/StringRefTest.cpp