|
|
|||
File indexing completed on 2026-05-10 08:36:19
0001 //===--- StringviewNullptrCheck.h - clang-tidy ------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRINGVIEWNULLPTRCHECK_H 0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRINGVIEWNULLPTRCHECK_H 0011 0012 #include "../utils/TransformerClangTidyCheck.h" 0013 0014 namespace clang::tidy::bugprone { 0015 0016 /// Checks for various ways that the `const CharT*` constructor of 0017 /// `std::basic_string_view` can be passed a null argument and replaces them 0018 /// with the default constructor in most cases. For the comparison operators, 0019 /// braced initializer list does not compile so instead a call to `.empty()` or 0020 /// the empty string literal are used, where appropriate. 0021 /// 0022 /// This prevents code from invoking behavior which is unconditionally 0023 /// undefined. The single-argument `const CharT*` constructor does not check 0024 /// for the null case before dereferencing its input. The standard is slated to 0025 /// add an explicitly-deleted overload to catch some of these cases: 0026 /// wg21.link/p2166 0027 /// 0028 /// To catch the additional cases of `NULL` (which expands to `__null`) and 0029 /// `0`, first run the ``modernize-use-nullptr`` check to convert the callers 0030 /// to `nullptr`. 0031 /// 0032 /// For the user-facing documentation see: 0033 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/stringview-nullptr.html 0034 class StringviewNullptrCheck : public utils::TransformerClangTidyCheck { 0035 public: 0036 StringviewNullptrCheck(StringRef Name, ClangTidyContext *Context); 0037 0038 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { 0039 return LangOpts.CPlusPlus17; 0040 } 0041 }; 0042 0043 } // namespace clang::tidy::bugprone 0044 0045 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_STRINGVIEWNULLPTRCHECK_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|