1// RUN: grep -Ev "// *[A-Z-]+:" %s > %t-input.cpp
2// RUN: not clang-tidy %t-input.cpp -checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes,clang-diagnostic-zero-length-array' --warnings-as-errors='clang-diagnostic-missing-prototypes,google-explicit-constructor' -export-fixes=%t.yaml -- -Wmissing-prototypes -Wzero-length-array > %t.msg 2>&1
3// RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s -implicit-check-not='{{warning|error|note}}:'
4// RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s
5#define X(n) void n ## n() {}
6X(f)
7int a[-1];
8int b[0];
9
10void test(x);
11struct Foo {
12 member;
13 Foo(int) {}
14};
15
16// CHECK-MESSAGES: -input.cpp:2:1: error: no previous prototype for function 'ff' [clang-diagnostic-missing-prototypes,-warnings-as-errors]
17// CHECK-MESSAGES: -input.cpp:1:19: note: expanded from macro 'X'
18// CHECK-MESSAGES: {{^}}note: expanded from here{{$}}
19// CHECK-MESSAGES: -input.cpp:2:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
20// CHECK-MESSAGES: -input.cpp:1:14: note: expanded from macro 'X'
21// CHECK-MESSAGES: -input.cpp:3:7: error: 'a' declared as an array with a negative size [clang-diagnostic-error]
22// CHECK-MESSAGES: -input.cpp:4:7: warning: zero size arrays are an extension [clang-diagnostic-zero-length-array]
23// CHECK-MESSAGES: -input.cpp:6:11: error: unknown type name 'x' [clang-diagnostic-error]
24// CHECK-MESSAGES: -input.cpp:8:3: error: a type specifier is required for all declarations [clang-diagnostic-error]
25// CHECK-MESSAGES: -input.cpp:9:3: error: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor,-warnings-as-errors]
26
27// CHECK-YAML: ---
28// CHECK-YAML-NEXT: MainSourceFile: '{{.*}}-input.cpp'
29// CHECK-YAML-NEXT: Diagnostics:
30// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-missing-prototypes
31// CHECK-YAML-NEXT: DiagnosticMessage:
32// CHECK-YAML-NEXT: Message: 'no previous prototype for function ''ff'''
33// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
34// CHECK-YAML-NEXT: FileOffset: 30
35// CHECK-YAML-NEXT: Replacements: []
36// CHECK-YAML-NEXT: Notes:
37// CHECK-YAML-NEXT: - Message: 'expanded from macro ''X'''
38// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
39// CHECK-YAML-NEXT: FileOffset: 18
40// CHECK-YAML-NEXT: Replacements: []
41// CHECK-YAML-NEXT: - Message: expanded from here
42// CHECK-YAML-NEXT: FilePath: ''
43// CHECK-YAML-NEXT: FileOffset: 0
44// CHECK-YAML-NEXT: Replacements: []
45// CHECK-YAML-NEXT: - Message: 'declare ''static'' if the function is not intended to be used outside of this translation unit'
46// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
47// CHECK-YAML-NEXT: FileOffset: 30
48// CHECK-YAML-NEXT: Replacements:
49// CHECK-YAML-NEXT: - FilePath: '{{.*}}-input.cpp'
50// CHECK-YAML-NEXT: Offset: 30
51// CHECK-YAML-NEXT: Length: 0
52// CHECK-YAML-NEXT: ReplacementText: 'static '
53// CHECK-YAML-NEXT: - Message: 'expanded from macro ''X'''
54// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
55// CHECK-YAML-NEXT: FileOffset: 13
56// CHECK-YAML-NEXT: Replacements: []
57// CHECK-YAML-NEXT: Level: Error
58// CHECK-YAML-NEXT: BuildDirectory: '{{.*}}'
59// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-error
60// CHECK-YAML-NEXT: DiagnosticMessage:
61// CHECK-YAML-NEXT: Message: '''a'' declared as an array with a negative size'
62// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
63// CHECK-YAML-NEXT: FileOffset: 41
64// CHECK-YAML-NEXT: Replacements: []
65// CHECK-YAML-NEXT: Ranges:
66// CHECK-YAML-NEXT: - FilePath: '{{.*}}-input.cpp'
67// CHECK-YAML-NEXT: FileOffset: 41
68// CHECK-YAML-NEXT: Length: 2
69// CHECK-YAML-NEXT: Level: Error
70// CHECK-YAML-NEXT: BuildDirectory: '{{.*}}'
71// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-zero-length-array
72// CHECK-YAML-NEXT: DiagnosticMessage:
73// CHECK-YAML-NEXT: Message: zero size arrays are an extension
74// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
75// CHECK-YAML-NEXT: FileOffset: 52
76// CHECK-YAML-NEXT: Replacements: []
77// CHECK-YAML-NEXT: Ranges:
78// CHECK-YAML-NEXT: - FilePath: '{{.*}}-input.cpp'
79// CHECK-YAML-NEXT: FileOffset: 52
80// CHECK-YAML-NEXT: Length: 1
81// CHECK-YAML-NEXT: Level: Warning
82// CHECK-YAML-NEXT: BuildDirectory: '{{.*}}'
83// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-error
84// CHECK-YAML-NEXT: DiagnosticMessage:
85// CHECK-YAML-NEXT: Message: 'unknown type name ''x'''
86// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
87// CHECK-YAML-NEXT: FileOffset: 67
88// CHECK-YAML-NEXT: Replacements: []
89// CHECK-YAML-NEXT: Level: Error
90// CHECK-YAML-NEXT: BuildDirectory: '{{.*}}'
91// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-error
92// CHECK-YAML-NEXT: DiagnosticMessage:
93// CHECK-YAML-NEXT: Message: a type specifier is required for all declarations
94// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
95// CHECK-YAML-NEXT: FileOffset: 86
96// CHECK-YAML-NEXT: Replacements: []
97// CHECK-YAML-NEXT: Level: Error
98// CHECK-YAML-NEXT: BuildDirectory: '{{.*}}'
99// CHECK-YAML-NEXT: - DiagnosticName: google-explicit-constructor
100// CHECK-YAML-NEXT: DiagnosticMessage:
101// CHECK-YAML-NEXT: Message: single-argument constructors must be marked explicit to avoid unintentional implicit conversions
102// CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp'
103// CHECK-YAML-NEXT: FileOffset: 96
104// CHECK-YAML-NEXT: Replacements:
105// CHECK-YAML-NEXT: - FilePath: '{{.*}}-input.cpp'
106// CHECK-YAML-NEXT: Offset: 96
107// CHECK-YAML-NEXT: Length: 0
108// CHECK-YAML-NEXT: ReplacementText: 'explicit '
109// CHECK-YAML-NEXT: Level: Error
110// CHECK-YAML-NEXT: BuildDirectory: '{{.*}}'
111// CHECK-YAML-NEXT: ...
112

source code of clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp