brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.8 KiB · b17e890 Raw
212 lines · cpp
1// RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- \2// RUN:   -header-filter='' -- \3// RUN:   -I%S/Inputs/reserved-identifier \4// RUN:   -isystem %S/Inputs/reserved-identifier/system5 6// no warnings expected with -header-filter=''7#include "user-header.h"8#include <system-header.h>9 10#define _MACRO(m) int m = 011// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '_MACRO', which is a reserved identifier [bugprone-reserved-identifier]12// CHECK-FIXES: #define MACRO(m) int m = 013 14namespace _Ns {15// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '_Ns', which is a reserved identifier [bugprone-reserved-identifier]16// CHECK-FIXES: namespace Ns {17 18class _Object {19  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Object', which is a reserved identifier [bugprone-reserved-identifier]20  // CHECK-FIXES: class Object {21  int _Member;22  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Member', which is a reserved identifier [bugprone-reserved-identifier]23  // CHECK-FIXES: int Member;24};25 26float _Global;27// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Global', which is a reserved identifier [bugprone-reserved-identifier]28// CHECK-FIXES: float Global;29 30void _Function() {}31// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_Function', which is a reserved identifier [bugprone-reserved-identifier]32// CHECK-FIXES: void Function() {}33 34using _Alias = int;35// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_Alias', which is a reserved identifier [bugprone-reserved-identifier]36// CHECK-FIXES: using Alias = int;37 38template <typename _TemplateParam>39// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier '_TemplateParam', which is a reserved identifier [bugprone-reserved-identifier]40// CHECK-FIXES: template <typename TemplateParam>41struct S {};42 43} // namespace _Ns44 45//46 47#define __macro(m) int m = 048// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier '__macro', which is a reserved identifier [bugprone-reserved-identifier]49// CHECK-FIXES: #define _macro(m) int m = 050 51namespace __ns {52// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '__ns', which is a reserved identifier [bugprone-reserved-identifier]53// CHECK-FIXES: namespace ns {54class __object {55  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__object', which is a reserved identifier [bugprone-reserved-identifier]56  // CHECK-FIXES: class _object {57  int __member;58  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__member', which is a reserved identifier [bugprone-reserved-identifier]59  // CHECK-FIXES: int _member;60};61 62float __global;63// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__global', which is a reserved identifier [bugprone-reserved-identifier]64// CHECK-FIXES: float _global;65 66void __function() {}67// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '__function', which is a reserved identifier [bugprone-reserved-identifier]68// CHECK-FIXES: void _function() {}69 70using __alias = int;71// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '__alias', which is a reserved identifier [bugprone-reserved-identifier]72// CHECK-FIXES: using _alias = int;73 74template <typename __templateParam>75// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier '__templateParam', which is a reserved identifier [bugprone-reserved-identifier]76// CHECK-FIXES: template <typename _templateParam>77struct S {};78 79} // namespace __ns80 81//82 83#define macro___m(m) int m = 084// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: declaration uses identifier 'macro___m', which is a reserved identifier [bugprone-reserved-identifier]85// CHECK-FIXES: #define macro_m(m) int m = 086 87namespace ns___n {88// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier 'ns___n', which is a reserved identifier [bugprone-reserved-identifier]89// CHECK-FIXES: namespace ns_n {90class object___o {91  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'object___o', which is a reserved identifier [bugprone-reserved-identifier]92  // CHECK-FIXES: class object_o {93  int member___m;94  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'member___m', which is a reserved identifier [bugprone-reserved-identifier]95  // CHECK-FIXES: int member_m;96};97 98float global___g;99// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'global___g', which is a reserved identifier [bugprone-reserved-identifier]100// CHECK-FIXES: float global_g;101 102void function___f() {}103// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier 'function___f', which is a reserved identifier [bugprone-reserved-identifier]104// CHECK-FIXES: void function_f() {}105 106using alias___a = int;107// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier 'alias___a', which is a reserved identifier [bugprone-reserved-identifier]108// CHECK-FIXES: using alias_a = int;109 110template <typename templateParam___t>111// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: declaration uses identifier 'templateParam___t', which is a reserved identifier [bugprone-reserved-identifier]112// CHECK-FIXES: template <typename templateParam_t>113struct S {};114 115} // namespace ns___n116 117//118 119// OK, this rule does not apply to macros:120// https://github.com/llvm/llvm-project/issues/64130#issuecomment-1655751676121#define _macro(m) int m = 0122 123namespace _ns {124// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration uses identifier '_ns', which is reserved in the global namespace [bugprone-reserved-identifier]125// CHECK-FIXES: namespace ns {126int _i;127// no warning128} // namespace _ns129class _object {130  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_object', which is reserved in the global namespace [bugprone-reserved-identifier]131  // CHECK-FIXES: class object {132  int _member;133  // no warning134};135float _global;136// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_global', which is reserved in the global namespace [bugprone-reserved-identifier]137// CHECK-FIXES: float global;138void _function() {}139// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_function', which is reserved in the global namespace [bugprone-reserved-identifier]140// CHECK-FIXES: void function() {}141using _alias = int;142// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration uses identifier '_alias', which is reserved in the global namespace [bugprone-reserved-identifier]143// CHECK-FIXES: using alias = int;144template <typename _templateParam> // no warning, template params are not in the global namespace145struct S {};146 147void _float() {}148// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_float', which is reserved in the global namespace; cannot be fixed because 'float' would conflict with a keyword [bugprone-reserved-identifier]149// CHECK-FIXES: void _float() {}150 151#define SOME_MACRO152int SOME__MACRO;153// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier 'SOME__MACRO', which is a reserved identifier; cannot be fixed because 'SOME_MACRO' would conflict with a macro definition [bugprone-reserved-identifier]154// CHECK-FIXES: int SOME__MACRO;155 156void _TWO__PROBLEMS() {}157// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_TWO__PROBLEMS', which is a reserved identifier [bugprone-reserved-identifier]158// CHECK-FIXES: void TWO_PROBLEMS() {}159void _two__problems() {}160// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration uses identifier '_two__problems', which is a reserved identifier [bugprone-reserved-identifier]161// CHECK-FIXES: void two_problems() {}162 163int __;164// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '__', which is a reserved identifier; cannot be fixed automatically [bugprone-reserved-identifier]165// CHECK-FIXES: int __;166 167int _________;168// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_________', which is a reserved identifier; cannot be fixed automatically [bugprone-reserved-identifier]169// CHECK-FIXES: int _________;170 171int _;172// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration uses identifier '_', which is reserved in the global namespace; cannot be fixed automatically [bugprone-reserved-identifier]173// CHECK-FIXES: int _;174 175// This should not trigger a warning176// https://github.com/llvm/llvm-project/issues/52895177#define _5_kmph_rpm 459178 179// these should pass180#define MACRO(m) int m = 0181 182namespace Ns {183class Object {184  int Member;185};186float Global;187 188void Function() {}189using Alias = int;190template <typename TemplateParam>191struct S {};192} // namespace Ns193namespace ns_ {194class object_ {195  int member_;196};197float global_;198void function_() {}199using alias_ = int;200template <typename templateParam_>201struct S {};202} // namespace ns_203 204class object_ {205  int member_;206};207float global_;208void function_() {}209using alias_ = int;210template <typename templateParam_>211struct S_ {};212