46 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRINGVIEWNULLPTRCHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRINGVIEWNULLPTRCHECK_H11 12#include "../utils/TransformerClangTidyCheck.h"13 14namespace clang::tidy::bugprone {15 16/// Checks for various ways that the `const CharT*` constructor of17/// `std::basic_string_view` can be passed a null argument and replaces them18/// with the default constructor in most cases. For the comparison operators,19/// braced initializer list does not compile so instead a call to `.empty()` or20/// the empty string literal are used, where appropriate.21///22/// This prevents code from invoking behavior which is unconditionally23/// undefined. The single-argument `const CharT*` constructor does not check24/// for the null case before dereferencing its input. The standard is slated to25/// add an explicitly-deleted overload to catch some of these cases:26/// wg21.link/p216627///28/// To catch the additional cases of `NULL` (which expands to `__null`) and29/// `0`, first run the ``modernize-use-nullptr`` check to convert the callers30/// to `nullptr`.31///32/// For the user-facing documentation see:33/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/stringview-nullptr.html34class StringviewNullptrCheck : public utils::TransformerClangTidyCheck {35public:36 StringviewNullptrCheck(StringRef Name, ClangTidyContext *Context);37 38 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {39 return LangOpts.CPlusPlus17;40 }41};42 43} // namespace clang::tidy::bugprone44 45#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRINGVIEWNULLPTRCHECK_H46