1 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=1 %s
2 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=2 %s
3 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=3 %s
4 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=4 %s
5 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=5 %s
8 auto test1a
= __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}
12 struct source_location
;
16 auto test1b
= __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}
20 struct source_location
{
25 auto test1c
= __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}
28 auto test2a
= __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}
32 struct source_location
{
33 struct __impl
{ int x
; };
37 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'}}
41 struct source_location
{
45 const char *_M_file_name
;
47 const char *_M_function_name
;
51 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'}}
55 struct source_location
{
57 struct __impl
: public parent
{
59 const char *_M_file_name
;
61 const char *_M_function_name
;
65 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'}}
70 struct source_location
{
72 signed char _M_line
; // odd integral type to choose, but ok!
73 const char *_M_file_name
;
74 signed char _M_column
;
75 const char *_M_function_name
;
76 static int other_member
; // static members are OK
78 using BuiltinT
= decltype(__builtin_source_location()); // OK.
82 // Verify that the address cannot be used as a non-type template argument.
83 template <auto X
= __builtin_source_location()>
84 auto fn1() {return X
;} // expected-note {{candidate template ignored: substitution failure: non-type template argument does not refer to any declaration}}
85 auto test5a
= fn1
<>(); // expected-error {{no matching function for call to 'fn1'}}
87 // (But using integer subobjects by value is okay.)
88 template <auto X
= __builtin_source_location()->_M_column
>
89 auto fn2() {return X
;}
90 auto test5b
= fn2
<>();
92 // While it's not semantically required, for efficiency, we ensure that two
93 // source-locations with the same content will point to the same object. Given
94 // the odd definition of the struct used here (using 'signed char'), any
95 // line-number modulo 256 will thus have the same content, and be deduplicated.
97 constexpr auto sl1
= __builtin_source_location();
99 constexpr auto sl2
= __builtin_source_location();
100 constexpr auto sl3
= __builtin_source_location();
101 static_assert(sl1
== sl2
);
102 static_assert(sl1
!= sl3
);
103 static_assert(sl1
->_M_line
== -128);