blob: 5b71f38c811f0c0f49f1ecd27da4004489ee3002 [file] [log] [blame]
// RUN: %clang -Wmissing-variable-declarations -fsyntax-only -Xclang -verify -std=c++17 %s
// Variable declarations that should trigger a warning.
int vbad1; // expected-warning{{no previous extern declaration for non-static variable 'vbad1'}}
int vbad2 = 10; // expected-warning{{no previous extern declaration for non-static variable 'vbad2'}}
namespace x {
int vbad3; // expected-warning{{no previous extern declaration for non-static variable 'vbad3'}}
}
// Variable declarations that should not trigger a warning.
static int vgood1;
extern int vgood2;
int vgood2;
static struct {
int mgood1;
} vgood3;
// Functions should never trigger a warning.
void fgood1(void);
void fgood2(void) {
int lgood1;
static int lgood2;
}
static void fgood3(void) {
int lgood3;
static int lgood4;
}
// Structures, namespaces and classes should be unaffected.
struct sgood1 {
int mgood2;
};
struct {
int mgood3;
} sgood2;
class CGood1 {
static int MGood1;
};
int CGood1::MGood1;
namespace {
int mgood4;
}
class C {
void test() {
static int x = 0; // no-warn
}
};
// There is also no need to use static in anonymous namespaces.
namespace {
int vgood4;
}
inline int inline_var = 0;
const int const_var = 0;
constexpr int constexpr_var = 0;
inline constexpr int inline_constexpr_var = 0;
extern const int extern_const_var = 0; // expected-warning {{no previous extern declaration}}
extern constexpr int extern_constexpr_var = 0; // expected-warning {{no previous extern declaration}}
template<typename> int var_template = 0;
template<typename> constexpr int const_var_template = 0;
template<typename> static int static_var_template = 0;
template int var_template<int[1]>;
int use_var_template() { return var_template<int[2]>; }
template int var_template<int[3]>;
extern template int var_template<int[4]>;
template<> int var_template<int[5]>; // expected-warning {{no previous extern declaration}}
// FIXME: We give this specialization internal linkage rather than inheriting
// the linkage from the template! We should not warn here.
template<> int static_var_template<int[5]>; // expected-warning {{no previous extern declaration}}