brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 975742d Raw
129 lines · cpp
1// RUN: %check_clang_tidy %s readability-redundant-declaration %t -- \2// RUN:   -config="{CheckOptions: \3// RUN:             {readability-redundant-declaration.IgnoreMacros: \4// RUN:                false}}"5//6// With -fms-compatibility and -DEXTERNINLINE, the extern inline shouldn't7// produce additional diagnostics, so same check suffix as before:8// RUN: %check_clang_tidy %s readability-redundant-declaration %t -- \9// RUN:   -config="{CheckOptions: \10// RUN:             {readability-redundant-declaration.IgnoreMacros: \11// RUN:                false}}" -- -fms-compatibility -DEXTERNINLINE12//13// With -fno-ms-compatibility, DEXTERNINLINE causes additional output.14// (The leading ',' means "default checks in addition to NOMSCOMPAT checks.)15// RUN: %check_clang_tidy -check-suffix=,NOMSCOMPAT \16// RUN:   %s readability-redundant-declaration %t -- \17// RUN:   -config="{CheckOptions: \18// RUN:             {readability-redundant-declaration.IgnoreMacros: \19// RUN:                false}}" -- -fno-ms-compatibility -DEXTERNINLINE20 21extern int Xyz;22extern int Xyz; // Xyz23// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Xyz' declaration [readability-redundant-declaration]24// CHECK-FIXES: // Xyz25int Xyz = 123;26 27extern int A;28extern int A, B;29// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'A' declaration30// CHECK-FIXES: extern int A, B;31 32extern int Buf[10];33extern int Buf[10]; // Buf[10]34// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'Buf' declaration35// CHECK-FIXES: // Buf[10]36 37static int f();38static int f(); // f39// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant 'f' declaration40// CHECK-FIXES: // f41static int f() { return 0; }42 43// Original check crashed for the code below.44namespace std {45typedef decltype(sizeof(0)) size_t;46}47void *operator new(std::size_t) __attribute__((__externally_visible__));48void *operator new[](std::size_t) __attribute__((__externally_visible__));49 50// Don't warn about static member definition.51struct C {52  static int I;53};54int C::I;55 56template <class T>57struct C2 {58  C2();59};60 61template <class T>62C2<T>::C2() = default;63 64void best_friend();65 66struct Friendly {67  friend void best_friend();68  friend void enemy();69};70 71void enemy();72 73template <typename>74struct TemplateFriendly {75  template <typename T>76  friend void generic_friend();77};78 79template <typename T>80void generic_friend() {}81 82TemplateFriendly<int> template_friendly;83 84template <typename>85struct TemplateFriendly2 {86  template <typename T>87  friend void generic_friend2() {}88};89 90template <typename T>91void generic_friend2();92 93void generic_friend_caller() {94  TemplateFriendly2<int> f;95  generic_friend2<int>();96}97 98 99namespace macros {100#define DECLARE(x) extern int x101#define DEFINE(x) extern int x; int x = 42102DECLARE(test);103DEFINE(test);104// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant 'test' declaration105// CHECK-FIXES: #define DECLARE(x) extern int x106// CHECK-FIXES: #define DEFINE(x) extern int x; int x = 42107// CHECK-FIXES: DECLARE(test);108// CHECK-FIXES: DEFINE(test);109 110} // namespace macros111 112inline void g() {}113 114inline void g(); // g115// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant 'g' declaration116// CHECK-FIXES: // g117 118#if defined(EXTERNINLINE)119extern inline void g(); // extern g120// CHECK-MESSAGES-NOMSCOMPAT: :[[@LINE-1]]:20: warning: redundant 'g' declaration121// CHECK-FIXES-NOMSCOMPAT: // extern g122#endif123 124// PR42068125extern "C" int externX;126int dummyBeforeBegin;extern "C" int externX;int dummyAfterEnd;127// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: redundant 'externX' declaration [readability-redundant-declaration]128// CHECK-FIXES: int dummyBeforeBegin;int dummyAfterEnd;129