File: diagnostic-order.cpp

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (73 lines) | stat: -rw-r--r-- 2,531 bytes parent folder | download | duplicates (30)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// RUN: not %clang_cc1 -std=c++11 %s -fsyntax-only 2>&1 | FileCheck %s
// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -DWARN 2>&1 | FileCheck %s --check-prefix=CHECK-WARN

#ifndef WARN

// Ensure that the diagnostics we produce for this situation appear in a
// deterministic order. This requires ADL to provide lookup results in a
// deterministic order.
template<typename T, typename> struct Error { typedef typename T::error error; };
struct X { template<typename T> friend typename Error<X, T>::error f(X, T); };
struct Y { template<typename T> friend typename Error<Y, T>::error f(T, Y); };

void g() {
  f(X(), Y());
}

// We don't really care which order these two diagnostics appear (although the
// order below is source order, which seems best). The crucial fact is that
// there is one single order that is stable across multiple runs of clang.
//
// CHECK: no type named 'error' in 'X'
// CHECK: no type named 'error' in 'Y'
// CHECK: no matching function for call to 'f'


struct Oper {
  template<typename T, typename U = typename Error<Oper, T>::error> operator T();

  operator int*();
  operator float*();
  operator X*();
  operator Y*();

  operator int(*[1])();
  operator int(*[2])();
  operator int(*[3])();
  operator int(*[4])();
  operator int(*[5])();
  operator int(*[6])();
  operator int(*[7])();
  operator int(*[8])();
  operator float(*[1])();
  operator float(*[2])();
  operator float(*[3])();
  operator float(*[4])();
  operator float(*[5])();
  operator float(*[6])();
  operator float(*[7])();
  operator float(*[8])();
};
int *p = Oper() + 0;

// CHECK: no type named 'error' in 'Oper'
// CHECK: in instantiation of template class 'Error<Oper, int *>'
// CHECK: no type named 'error' in 'Oper'
// CHECK: in instantiation of template class 'Error<Oper, float *>'
// CHECK: no type named 'error' in 'Oper'
// CHECK: in instantiation of template class 'Error<Oper, X *>'
// CHECK: no type named 'error' in 'Oper'
// CHECK: in instantiation of template class 'Error<Oper, Y *>'

#endif

template<typename T> struct UndefButUsed {
  static inline int f();
  static int g() { return f(); }
};
int undef_but_used = UndefButUsed<int>::g() + UndefButUsed<float>::g() + UndefButUsed<char>::g() + UndefButUsed<void>::g();

// CHECK-WARN: inline function 'UndefButUsed<int>::f' is not defined
// CHECK-WARN: inline function 'UndefButUsed<float>::f' is not defined
// CHECK-WARN: inline function 'UndefButUsed<char>::f' is not defined
// CHECK-WARN: inline function 'UndefButUsed<void>::f' is not defined