1 // RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-variable-declarations -std=c++17 %s
3 // Variable declarations that should trigger a warning.
4 int 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}}
7 int 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}}
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}}
15 // Variable declarations that should not trigger a warning.
23 // Functions should never trigger a warning.
29 static void fgood3(void) {
34 // Structures, namespaces and classes should be unaffected.
51 static int x
= 0; // no-warn
55 // There is also no need to use static in anonymous namespaces.
60 inline int inline_var
= 0;
61 const int const_var
= 0;
62 constexpr int constexpr_var
= 0;
63 inline constexpr int inline_constexpr_var
= 0;
64 extern 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}}
66 extern 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}}
69 template<typename
> int var_template
= 0;
70 template<typename
> constexpr int const_var_template
= 0;
71 template<typename
> static int static_var_template
= 0;
73 template<typename T
> int var_template
<T
*>;
75 template int var_template
<int[1]>;
76 int use_var_template() { return var_template
<int[2]>; }
77 template int var_template
<int[3]>;
78 extern template int var_template
<int[4]>;
79 template<> 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}}
82 // FIXME: We give this specialization internal linkage rather than inheriting
83 // the linkage from the template! We should not warn here.
84 template<> 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}}