brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · b50eeed Raw
86 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-variable-declarations -std=c++17 %s2 3// Variable declarations that should trigger a warning.4int vbad1; // expected-warning{{no previous extern declaration for non-static variable 'vbad1'}}5// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}6 7int vbad2 = 10; // expected-warning{{no previous extern declaration for non-static variable 'vbad2'}}8// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}9 10namespace x {11  int vbad3; // expected-warning{{no previous extern declaration for non-static variable 'vbad3'}}12  // expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}13}14 15// Variable declarations that should not trigger a warning.16static int vgood1;17extern int vgood2;18int vgood2;19static struct {20  int mgood1;21} vgood3;22 23// Functions should never trigger a warning.24void fgood1(void);25void fgood2(void) {26  int lgood1;27  static int lgood2;28}29static void fgood3(void) {30  int lgood3;31  static int lgood4;32}33 34// Structures, namespaces and classes should be unaffected.35struct sgood1 {36  int mgood2;37};38struct {39  int mgood3;40} sgood2;41class CGood1 {42  static int MGood1;43};44int CGood1::MGood1;45namespace {46  int mgood4;47}48 49class C {50  void test() {51    static int x = 0; // no-warn52  }53};54 55// There is also no need to use static in anonymous namespaces.56namespace {57  int vgood4;58}59 60inline int inline_var = 0;61const int const_var = 0;62constexpr int constexpr_var = 0;63inline constexpr int inline_constexpr_var = 0;64extern const int extern_const_var = 0; // expected-warning {{no previous extern declaration}}65// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}66extern constexpr int extern_constexpr_var = 0; // expected-warning {{no previous extern declaration}}67// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}68 69template<typename> int var_template = 0;70template<typename> constexpr int const_var_template = 0;71template<typename> static int static_var_template = 0;72 73template<typename T> int var_template<T*>;74 75template int var_template<int[1]>;76int use_var_template() { return var_template<int[2]>; }77template int var_template<int[3]>;78extern template int var_template<int[4]>;79template<> int var_template<int[5]>; // expected-warning {{no previous extern declaration}}80// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}81 82// FIXME: We give this specialization internal linkage rather than inheriting83// the linkage from the template! We should not warn here.84template<> int static_var_template<int[5]>; // expected-warning {{no previous extern declaration}}85// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}86