File: source_location_err.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (105 lines) | stat: -rw-r--r-- 3,775 bytes parent folder | download | duplicates (13)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=1 %s
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=2 %s
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=3 %s
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=4 %s
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=5 %s

#if TEST == 1
auto test1a = __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}

namespace std {
inline namespace NS {
  struct source_location;
}
}

auto test1b = __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}

namespace std {
inline namespace NS {
  struct source_location {
    struct __impl;
  };
}
}
auto test1c = __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}

#elif TEST == 2
auto test2a = __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}

namespace std {
inline namespace NS {
struct source_location {
  struct __impl { int x; };
};
}
}
auto test2b = __builtin_source_location(); // expected-error {{'std::source_location::__impl' must be standard-layout and have only two 'const char *' fields '_M_file_name' and '_M_function_name', and two integral fields '_M_line' and '_M_column'}}

#elif TEST == 3
namespace std {
struct source_location {
  struct __impl {
    int other_member;
    char _M_line;
    const char *_M_file_name;
    char _M_column;
    const char *_M_function_name;
  };
};
}
auto test3 = __builtin_source_location(); // expected-error {{'std::source_location::__impl' must be standard-layout and have only two 'const char *' fields '_M_file_name' and '_M_function_name', and two integral fields '_M_line' and '_M_column'}}

#elif TEST == 4
namespace std {
struct source_location {
  struct parent {};
  struct __impl : public parent {
    char _M_line;
    const char *_M_file_name;
    char _M_column;
    const char *_M_function_name;
  };
};
}
auto test4 = __builtin_source_location(); // expected-error {{'std::source_location::__impl' must be standard-layout and have only two 'const char *' fields '_M_file_name' and '_M_function_name', and two integral fields '_M_line' and '_M_column'}}


#elif TEST == 5
namespace std {
struct source_location {
  struct __impl {
    signed char _M_line; // odd integral type to choose, but ok!
    const char *_M_file_name;
    signed char _M_column;
    const char *_M_function_name;
    static int other_member; // static members are OK
  };
  using BuiltinT = decltype(__builtin_source_location()); // OK.
};
}

// Verify that the address cannot be used as a non-type template argument.
template <auto X = __builtin_source_location()>
auto fn1() {return X;} // expected-note {{candidate template ignored: substitution failure: non-type template argument does not refer to any declaration}}
auto test5a = fn1<>(); // expected-error {{no matching function for call to 'fn1'}}

// (But using integer subobjects by value is okay.)
template <auto X = __builtin_source_location()->_M_column>
auto fn2() {return X;}
auto test5b = fn2<>();

// While it's not semantically required, for efficiency, we ensure that two
// source-locations with the same content will point to the same object. Given
// the odd definition of the struct used here (using 'signed char'), any
// line-number modulo 256 will thus have the same content, and be deduplicated.
#line 128
constexpr auto sl1 = __builtin_source_location();
#line 384
constexpr auto sl2 = __builtin_source_location();
constexpr auto sl3 = __builtin_source_location();
static_assert(sl1 == sl2);
static_assert(sl1 != sl3);
static_assert(sl1->_M_line == -128);

#endif