Differential D118743 Diff 416347 clang-tools-extra/test/clang-tidy/checkers/modernize-use-inline-const-variables-in-headers.hpp
Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/test/clang-tidy/checkers/modernize-use-inline-const-variables-in-headers.hpp
- This file was added.
// RUN: %check_clang_tidy %s -std=c++17 modernize-use-inline-const-variables-in-headers %t | |||||
const int ConstFoo = 1; | |||||
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: global constant 'ConstFoo' should be marked as 'inline' [modernize-use-inline-const-variables-in-headers] | |||||
// CHECK-FIXES: {{^}}inline const int ConstFoo = 1;{{$}} | |||||
namespace N { | |||||
constexpr int NamespaceFoo = 1; | |||||
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: global constant 'NamespaceFoo' should be marked as 'inline' [modernize-use-inline-const-variables-in-headers] | |||||
// CHECK-FIXES: {{^}}inline constexpr int NamespaceFoo = 1;{{$}} | |||||
} // namespace N | |||||
extern const int ExternFoo; | |||||
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: global constant 'ExternFoo' should be converted to C++17 'inline variable' [modernize-use-inline-const-variables-in-headers] | |||||
struct S { | |||||
// no warning: the variable is not at file scope | |||||
static const int StructFoo = 1; | |||||
}; | |||||
// no warning: non-const global variables have external linkage | |||||
int NonConstFoo = 1; | |||||
// no warning: volatile global variables have external linkage | |||||
const volatile int VolatileFoo = 1; | |||||
// no warning: templates and their instantiations have external linkage | |||||
template <typename T> | |||||
const auto TemplateFoo = sizeof(T); | |||||
// no warning: already fixed | |||||
inline const int InlineFoo = 1; | |||||
// no warning: C has no 'inline variables' | |||||
extern "C" { | |||||
const int CFoo0 = 1; | |||||
} | |||||
extern "C" const int CFoo1 = 1; | |||||
// no warning: 'inline' is invisible when within an unnamed namespace | |||||
namespace { | |||||
const int AnonNamespaceFoo = 1; | |||||
} // namespace |