File: inconsistent-declaration-parameter-name-macros.cpp

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (46 lines) | stat: -rw-r--r-- 2,127 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// RUN: %check_clang_tidy %s readability-inconsistent-declaration-parameter-name %t -- \
// RUN:   -config="{CheckOptions: [{key: readability-inconsistent-declaration-parameter-name.IgnoreMacros, value: false}]}"

#define MACRO() \
  void f(int x)

struct S1 {
  MACRO();
  // CHECK-NOTES: :[[@LINE-1]]:3: warning: function 'S1::f' has a definition with different parameter names
  // CHECK-NOTES: :[[@LINE-5]]:8: note: expanded from macro 'MACRO'
  // CHECK-NOTES: :[[@LINE+4]]:10: note: the definition seen here
  // CHECK-NOTES: :[[@LINE-4]]:3: note: differing parameters are named here: ('x'), in definition: ('y')
  // CHECK-NOTES: :[[@LINE-8]]:8: note: expanded from macro 'MACRO'
};
void S1::f(int y) {}

struct S2 {
  int g() const;
  void set_g(int g);
  // CHECK-NOTES: :[[@LINE-1]]:8: warning: function 'S2::set_g' has a definition with different parameter names
  // CHECK-NOTES: :[[@LINE+14]]:1: note: the definition seen here
  // CHECK-NOTES: :[[@LINE+9]]:12: note: expanded from macro 'DEFINITION'
  // This one is unfortunate, but the location this points to is in a scratch
  // space, so it's not helpful to the user.
  // CHECK-NOTES: {{^}}note: expanded from here{{$}}
  // CHECK-NOTES: :[[@LINE-7]]:8: note: differing parameters are named here: ('g'), in definition: ('w')
};

#define DEFINITION(name, parameter)    \
  int S2::name() const { return 0; }   \
  void S2::set_##name(int parameter) { \
    (void)parameter;                   \
  }

DEFINITION(g, w)

//////////////////////////////////////////////////////

#define DECLARE_FUNCTION_WITH_PARAM_NAME(function_name, param_name) \
  void function_name(int param_name)

// CHECK-NOTES: :[[@LINE+1]]:34: warning: function 'macroFunction' has 1 other declaration with different parameter names [readability-inconsistent-declaration-parameter-name]
DECLARE_FUNCTION_WITH_PARAM_NAME(macroFunction, a);
// CHECK-NOTES: :[[@LINE+2]]:34: note: the 1st inconsistent declaration seen here
// CHECK-NOTES: :[[@LINE+1]]:34: note: differing parameters are named here: ('b'), in the other declaration: ('a')
DECLARE_FUNCTION_WITH_PARAM_NAME(macroFunction, b);